Which of the following can terminate a while loop and transfer control outside the loop? 1) exit 2) while 3) continue 4) break 5) goto

Difficulty: Easy

Correct Answer: 4, 5

Explanation:

Introduction / Context:Loop control in C# uses structured jump statements to exit or skip iterations. Knowing which statements actually leave the loop is key.

Given Data / Assumptions:

  • Five tokens are listed; some are not C# keywords.
  • Goal: identify statements that exit a while loop.

Concept / Approach:“break” exits the nearest loop. “goto” can jump to a label outside the loop (within the same method). “continue” skips only to the next iteration. “exit” and “exit statement” are not C# keywords (Environment.Exit exists but is not a statement).

Step-by-Step Solution:

Evaluate each item vs C# syntax.1) exit — not a C# statement.2) while — loop keyword, not an exit.3) continue — stays in loop, next iteration.4) break — exits loop immediately.5) goto — may transfer control to a label; if label is outside loop, effect is loop exit.

Verification / Alternative check:Any C# reference shows “break” and “goto” as valid jump statements.

Why Other Options Are Wrong:

  • 1, 3: Neither exits.
  • 2, 4: Includes “while”.
  • 3, 5: “continue” does not exit.
  • None of these: incorrect because 4 and 5 do exit.

Common Pitfalls:Confusing “continue” with “break”.

Final Answer:4, 5

More Questions from Control Instructions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion