Difficulty: Easy
Correct Answer: Prints 1 to 9
Explanation:
Introduction / Context:
Although goto is rarely recommended in modern C#, this example demonstrates a manual loop using a label and a conditional jump. The question asks you to trace which values of i are printed before the condition fails.
Given Data / Assumptions:
Concept / Approach:
Observe the sequence: increment i, update j, test i < 10, print i, and loop via goto. Because i is incremented before the test, the printed sequence begins at 1 and ends at 9, stopping when i becomes 10 (which fails the if condition and the jump does not occur).
Step-by-Step Solution:
Verification / Alternative check:
Replace goto with a while: i = 0; while (i < 9) { i++; Console.Write(i + " "); } → prints 1..9.
Why Other Options Are Wrong:
Common Pitfalls:
Expecting 10 to print; the condition prevents printing when i equals 10.
Final Answer:
Prints 1 to 9
Discussion & Comments