HomeSubjectsUniversityBlogAbout

Control Structures

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

Control structures are language constructs that decide the order in which statements run, using selection, repetition and jumps instead of straight lines. MCQs trace if-else chains, switch statements with fall-through, missing break statements and default cases. Loop questions compare for, while and do-while, count iterations of nested loops, and catch off-by-one errors and infinite loops. Know exactly what break, continue and return do inside a loop and why goto is discouraged by structured programming. Advanced items cover guard clauses for early exit, continuation-passing style, computed goto in low-level code and structured concurrency as a way of scoping control flow.

Below are 30 practice questions from a pool of 210 Control Structures MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

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?

  1. A.Declares a new variable in the scope
  2. B.Defines a reusable function or method
  3. C.Executes code only if condition is true✓ Correct
  4. 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?

  1. A.A conditional branching statement
  2. B.A construct that repeats code blocks✓ Correct
  3. C.A syntax for declaring variables
  4. 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?

  1. A.To terminate the entire program execution
  2. B.To execute code when if condition is false✓ Correct
  3. C.To define a reusable function or procedure
  4. 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?

  1. A.both of them
  2. B.do-while loop
  3. C.neither of them
  4. 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?

  1. A.Restarts the loop from start
  2. B.Terminates the loop entirely✓ Correct
  3. C.Pauses the loop temporarily
  4. 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?

  1. A.4
  2. B.0
  3. C.5✓ Correct
  4. 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?

  1. A.A syntax for declaring new functions
  2. B.A type of iterative loop construct
  3. C.A multi-way branch on expression value✓ Correct
  4. 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?

  1. A.Restarts the loop from the very beginning
  2. B.Skips rest of iteration and moves to next✓ Correct
  3. C.Pauses execution until user gives input
  4. 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?

  1. A.A loop that has been terminated
  2. B.A loop without any condition set
  3. C.A loop that runs only one time
  4. 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');?

  1. A.BA
  2. B.AB
  3. C.A
  4. 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?

  1. A.do-while is faster in execution speed compared to while loop
  2. B.while always runs the loop body at least one time guaranteed
  3. C.while checks condition first; do-while runs body at least once✓ Correct
  4. 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?

  1. A.A syntax error detected at compile time
  2. B.A loop that has an empty body
  3. C.A loop whose condition never becomes false✓ Correct
  4. 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?

  1. A.It executes when no other case matches✓ Correct
  2. B.It is required in every switch
  3. C.It must always be first
  4. 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?

  1. A.Execution continues to next case without break✓ Correct
  2. B.A compilation error in the switch block
  3. C.The switch statement fails and throws an error
  4. 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?

  1. A.A special value signaling loop termination✓ Correct
  2. B.A constant defined in the loop body
  3. C.A randomly generated input value
  4. 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?

  1. A.O(n)
  2. B.O(2^n)
  3. C.O(log n)
  4. 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?

  1. A.A loop that counts its own iterations explicitly
  2. B.A loop that runs indefinitely until interrupted
  3. C.A loop that skips every other element in turn
  4. 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?

  1. A.A compilation error is raised by the compiler immediately
  2. B.Nothing happens and the switch works as normally expected
  3. C.The program crashes with an unrecoverable runtime error
  4. 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?

  1. A.A break that exits a specific labeled outer loop✓ Correct
  2. B.A break statement followed by a comment
  3. C.A syntax error that the compiler will reject
  4. 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?

  1. A.Making loops intentionally execute more slowly for debugging
  2. B.Reducing loop overhead by executing multiple iterations per pass✓ Correct
  3. C.Adding additional iterations to increase the loop precision
  4. 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?

  1. A.Recursion that uses a tail pointer data structure
  2. B.Recursion without any base case for termination
  3. C.A loop structure that invokes itself recursively
  4. 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?

  1. A.Structured control flow is slower than unstructured control
  2. B.Unstructured control flow is more readable than structured
  3. C.There is no meaningful difference between the two approaches
  4. 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?

  1. A.Matching strings with regular expressions
  2. B.A generalized switch that destructures data types✓ Correct
  3. C.A repeating pattern within a loop construct
  4. 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?

  1. A.Eager evaluates expressions immediately; lazy defers until value needed✓ Correct
  2. B.Lazy evaluation is always faster than eager evaluation in all cases
  3. C.Eager evaluation is only used in purely functional language paradigms
  4. 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?

  1. A.A coroutine is a specialized type of loop iteration control structure
  2. B.A subroutine can be paused and resumed at arbitrary execution points
  3. C.They are the same thing with different names in different languages
  4. 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?

  1. A.To lock and protect shared resources from concurrent thread access
  2. B.To guard against invalid memory allocation during program startup
  3. C.To protect systems against unauthorized network access attempts
  4. 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?

  1. A.A technique converting recursion into iterative loops✓ Correct
  2. B.A specialized debugging tool for stack overflow
  3. C.A physical device used for hardware testing
  4. 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?

  1. A.A loop continuation condition for iterations
  2. B.An alternative to the break statement in loops
  3. C.The next sequential statement in the code
  4. 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?

  1. A.There is no practical difference between them at all
  2. B.Deterministic follows a fixed path; non-deterministic explores many✓ Correct
  3. C.Non-deterministic control flow always causes the program to crash
  4. 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?

  1. A.Goto should be used everywhere as the primary control flow method
  2. B.Goto causes memory leaks and resource allocation failures in code
  3. C.Dijkstra argued goto makes programs hard to follow and reason about✓ Correct
  4. 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

Ready to test yourself on Control Structures?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Control Structures Quiz