Difficulty: Medium
Correct Answer: i = 5 and j = 6
Explanation:
Introduction / Context:
This trace problem tests order of evaluation in do-while loops, the effect of a pre-increment (++i) in the loop condition, and control-flow with break. You must track i and j across iterations.
Given Data / Assumptions:
Concept / Approach:
A do-while executes the body at least once. After each body, j is decremented, then i is pre-incremented for the condition check. The break guard if(i > j) is evaluated at the top of each iteration before decrementing j. Carefully update the variables step by step.
Step-by-Step Solution:
Verification / Alternative check:
Note that the if(i > j) never triggers; j remains larger until exit. A quick table confirms the sequence.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that do-while checks condition after the body and that ++i changes i before comparison.
Final Answer:
i = 5 and j = 6
Discussion & Comments