Difficulty: Medium
Correct Answer: i = 5 and j = 6
Explanation:
Introduction / Context:
This problem exercises short, precise reasoning about post-increment and pre-decrement inside a conditional, plus the behavior of continue
within a do-while
loop. Understanding evaluation order is crucial to get the final values correct.
Given Data / Assumptions:
i++
(returns old i, then increments) and --j
(decrements then returns).continue
skips to the while-condition check at the loop bottom.
Concept / Approach:
Trace each iteration carefully and update i and j in the exact order the expression evaluates: left operand i++
first (post-increment), right operand --j
second (pre-decrement), then compare. The body has no other state changes except potential continue
(which still executes the loop condition afterward).
Step-by-Step Solution:
Verification / Alternative check:
Because the if-condition never becomes true, continue
never fires; only the implicit increments from the condition update i
and j
each time. Final: i = 5, j = 6.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that i++
returns the old value while still incrementing afterward; and that --j
decrements before comparison.
Final Answer:
i = 5 and j = 6
Discussion & Comments