Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Control StructuresEasy
Q1. What does an if statement do?
- A.Declares a new variable in the scope
- B.Defines a reusable function or method
- C.Executes code only if condition is true✓ Correct
- D.Repeats a block of code in a loop
Explanation
An if statement evaluates a condition and executes the associated block of code only when the condition is true.
Report an error in this question
Control StructuresEasy
Q2. What is a loop?
- A.A conditional branching statement
- B.A construct that repeats code blocks✓ Correct
- C.A syntax for declaring variables
- D.A mechanism for calling functions
Explanation
A loop is a control structure that repeatedly executes a block of code while a condition is met.
Report an error in this question
Control StructuresEasy
Q3. What is the purpose of the 'else' clause?
- A.To terminate the entire program execution
- B.To execute code when if condition is false✓ Correct
- C.To define a reusable function or procedure
- D.To start a new loop iteration immediately
Explanation
The else clause provides an alternative block of code that executes when the if condition evaluates to false.
Report an error in this question
Control StructuresEasy
Q4. Which loop checks the condition before executing the body?
- A.both of them
- B.do-while loop
- C.neither of them
- D.while loop✓ Correct
Explanation
A while loop evaluates its condition before each iteration; if false initially, the body never executes.
Report an error in this question
Control StructuresEasy
Q5. What does the 'break' statement do in a loop?
- A.Restarts the loop from start
- B.Terminates the loop entirely✓ Correct
- C.Pauses the loop temporarily
- D.Skips the current iteration only
Explanation
The break statement immediately terminates the enclosing loop and continues execution after the loop.
Report an error in this question
Control StructuresEasy
Q6. How many times does a for loop 'for(int i=0; i<5; i++)' execute?
- A.4
- B.0
- C.5✓ Correct
- D.6
Explanation
The loop runs for i = 0, 1, 2, 3, 4, which is 5 iterations.
Report an error in this question
Control StructuresEasy
Q7. What is a switch statement?
- A.A syntax for declaring new functions
- B.A type of iterative loop construct
- C.A multi-way branch on expression value✓ Correct
- D.A mechanism for handling exceptions
Explanation
A switch statement evaluates an expression and branches to the matching case label for execution.
Report an error in this question
Control StructuresEasy
Q8. What does the 'continue' statement do?
- A.Restarts the loop from the very beginning
- B.Skips rest of iteration and moves to next✓ Correct
- C.Pauses execution until user gives input
- D.Exits and terminates the entire loop
Explanation
The continue statement skips the remaining statements in the current loop iteration and proceeds to the next iteration.
Report an error in this question
Control StructuresEasy
Q9. What is a nested loop?
- A.A loop that has been terminated
- B.A loop without any condition set
- C.A loop that runs only one time
- D.A loop placed inside another loop✓ Correct
Explanation
A nested loop is a loop placed inside the body of another loop; the inner loop completes all iterations for each iteration of the outer loop.
Report an error in this question
Control StructuresEasy
Q10. What is the output of: if(false) print('A'); else print('B');?
- A.BA
- B.AB
- C.A
- D.B✓ Correct
Explanation
Since the condition is false, the else branch executes and prints 'B'.
Report an error in this question
Control StructuresMedium
Q11. What is the difference between while and do-while loops?
- A.do-while is faster in execution speed compared to while loop
- B.while always runs the loop body at least one time guaranteed
- C.while checks condition first; do-while runs body at least once✓ Correct
- D.There is no meaningful difference between them at all
Explanation
A do-while loop executes the body first then checks the condition, guaranteeing at least one execution.
Report an error in this question
Control StructuresMedium
Q12. What is an infinite loop?
- A.A syntax error detected at compile time
- B.A loop that has an empty body
- C.A loop whose condition never becomes false✓ Correct
- D.A loop that executes very fast
Explanation
An infinite loop is one where the termination condition is never met, causing it to run indefinitely unless externally interrupted.
Report an error in this question
Control StructuresMedium
Q13. What is the purpose of the 'default' case in a switch statement?
- A.It executes when no other case matches✓ Correct
- B.It is required in every switch
- C.It must always be first
- D.It resets the switch value
Explanation
The default case executes when the switch expression does not match any of the specified case labels.
Report an error in this question
Control StructuresMedium
Q14. What is fall-through in a switch statement?
- A.Execution continues to next case without break✓ Correct
- B.A compilation error in the switch block
- C.The switch statement fails and throws an error
- D.The default case gets skipped during execution
Explanation
Fall-through occurs when a case does not have a break statement, causing execution to continue into subsequent cases.
Report an error in this question
Control StructuresMedium
Q15. What is a sentinel value in loop control?
- A.A special value signaling loop termination✓ Correct
- B.A constant defined in the loop body
- C.A randomly generated input value
- D.A variable used as a loop counter
Explanation
A sentinel value is a special value used to indicate the end of a sequence or that a loop should terminate.
Report an error in this question
Control StructuresMedium
Q16. What is the time complexity of a nested loop where both run n times?
- A.O(n)
- B.O(2^n)
- C.O(log n)
- D.O(n^2)✓ Correct
Explanation
When one loop of n iterations contains another loop of n iterations, the total iterations are n * n = O(n^2).
Report an error in this question
Control StructuresMedium
Q17. What is a for-each loop?
- A.A loop that counts its own iterations explicitly
- B.A loop that runs indefinitely until interrupted
- C.A loop that skips every other element in turn
- D.A loop iterating over each element without index✓ Correct
Explanation
A for-each (enhanced for) loop iterates over every element in a collection or array without requiring an index variable.
Report an error in this question
Control StructuresMedium
Q18. What happens if you forget the break in a switch case in Java?
- A.A compilation error is raised by the compiler immediately
- B.Nothing happens and the switch works as normally expected
- C.The program crashes with an unrecoverable runtime error
- D.Fall-through: subsequent cases execute until a break is hit✓ Correct
Explanation
Without break, execution falls through to subsequent case blocks until a break statement or the end of the switch is encountered.
Report an error in this question
Control StructuresMedium
Q19. What is a labeled break statement?
- A.A break that exits a specific labeled outer loop✓ Correct
- B.A break statement followed by a comment
- C.A syntax error that the compiler will reject
- D.A break statement that logs a debug message
Explanation
A labeled break allows breaking out of a specific outer loop by referencing its label, useful for nested loops.
Report an error in this question
Control StructuresMedium
Q20. What is loop unrolling?
- A.Making loops intentionally execute more slowly for debugging
- B.Reducing loop overhead by executing multiple iterations per pass✓ Correct
- C.Adding additional iterations to increase the loop precision
- D.Removing a loop from the code entirely
Explanation
Loop unrolling is a compiler optimization that replicates the loop body multiple times to reduce the overhead of loop control.
Report an error in this question
Control StructuresHard
Q21. What is tail recursion and how does it relate to loops?
- A.Recursion that uses a tail pointer data structure
- B.Recursion without any base case for termination
- C.A loop structure that invokes itself recursively
- D.A tail-position recursive call optimized into a loop✓ Correct
Explanation
Tail recursion occurs when the recursive call is the last operation; compilers can optimize it into an iterative loop, avoiding stack growth.
Report an error in this question
Control StructuresHard
Q22. What is the difference between structured and unstructured control flow?
- A.Structured control flow is slower than unstructured control
- B.Unstructured control flow is more readable than structured
- C.There is no meaningful difference between the two approaches
- D.Structured uses blocks like if/while; unstructured uses goto✓ Correct
Explanation
Structured control flow uses well-defined blocks (if, while, for) while unstructured flow uses goto/jump statements, making code harder to reason about.
Report an error in this question
Control StructuresHard
Q23. What is pattern matching as a control structure?
- A.Matching strings with regular expressions
- B.A generalized switch that destructures data types✓ Correct
- C.A repeating pattern within a loop construct
- D.A text search algorithm for finding substrings
Explanation
Pattern matching (as in Rust, Scala, Haskell) goes beyond switch by destructuring data and matching against structural patterns with exhaustiveness checking.
Report an error in this question
Control StructuresHard
Q24. What is the difference between eager and lazy evaluation in control flow?
- A.Eager evaluates expressions immediately; lazy defers until value needed✓ Correct
- B.Lazy evaluation is always faster than eager evaluation in all cases
- C.Eager evaluation is only used in purely functional language paradigms
- D.There is no practical difference between the two evaluation strategies
Explanation
Eager evaluation computes values as soon as they are bound; lazy evaluation defers computation until the value is actually required, enabling infinite data structures.
Report an error in this question
Control StructuresHard
Q25. What is a coroutine and how does it differ from a subroutine?
- A.A coroutine is a specialized type of loop iteration control structure
- B.A subroutine can be paused and resumed at arbitrary execution points
- C.They are the same thing with different names in different languages
- D.A coroutine can suspend and resume; a subroutine runs to completion✓ Correct
Explanation
Coroutines can suspend execution and be resumed later, maintaining their state between suspensions, unlike subroutines which run to completion once called.
Report an error in this question
Control StructuresHard
Q26. What is the purpose of guard clauses?
- A.To lock and protect shared resources from concurrent thread access
- B.To guard against invalid memory allocation during program startup
- C.To protect systems against unauthorized network access attempts
- D.To handle edge cases early by returning at the start of functions✓ Correct
Explanation
Guard clauses handle preconditions and edge cases at the start of a function, returning or throwing early to avoid deep nesting of the main logic.
Report an error in this question
Control StructuresHard
Q27. What is a trampoline in the context of recursion?
- A.A technique converting recursion into iterative loops✓ Correct
- B.A specialized debugging tool for stack overflow
- C.A physical device used for hardware testing
- D.A tree-based data structure for fast lookup
Explanation
A trampoline wraps recursive calls in thunks and uses a loop to iteratively evaluate them, preventing stack overflow in languages without tail call optimization.
Report an error in this question
Control StructuresHard
Q28. What is continuation in control flow?
- A.A loop continuation condition for iterations
- B.An alternative to the break statement in loops
- C.The next sequential statement in the code
- D.An abstract representation of remaining computation✓ Correct
Explanation
A continuation represents the remaining computation from a given point in the program, allowing capture and invocation of the rest of the program.
Report an error in this question
Control StructuresHard
Q29. What is the difference between deterministic and non-deterministic control flow?
- A.There is no practical difference between them at all
- B.Deterministic follows a fixed path; non-deterministic explores many✓ Correct
- C.Non-deterministic control flow always causes the program to crash
- D.Deterministic control flow always executes more slowly than others
Explanation
Deterministic control flow follows one fixed execution path; non-deterministic control flow can explore multiple execution paths.
Report an error in this question
Control StructuresHard
Q30. What is the 'goto considered harmful' argument?
- A.Goto should be used everywhere as the primary control flow method
- B.Goto causes memory leaks and resource allocation failures in code
- C.Dijkstra argued goto makes programs hard to follow and reason about✓ Correct
- D.Goto is always the most efficient control flow mechanism available
Explanation
Dijkstra's 1968 letter argued that unrestricted goto makes programs hard to understand and verify, leading to the structured programming movement.
Report an error in this question