1Z0-809 · Question #43
Given the for loop construct: for ( expr1 ; expr2 ; expr3 ) { statement; } Which two statements are true?
The correct answer is B. The expression expr1 is optional. It initializes the loop and is evaluated once, as the loop begins. C. When expr2 evaluates to false, the loop terminates. It is evaluated only after each iteration through the loop. B is correct because expr1 is indeed optional - you can omit it (e.g., for (; expr2; expr3)) - and when present, it runs exactly once before the loop begins, making both claims in B accurate. C is correct because expr2 acts as the loop's exit condition: when it evaluates to…
Question
Options
- AThis is not the only valid for loop construct: there exits another form of for loop constructor.
- BThe expression expr1 is optional. It initializes the loop and is evaluated once, as the loop begins.
- CWhen expr2 evaluates to false, the loop terminates. It is evaluated only after each iteration through the loop.
- DThe expression expr3 must be present. It is evaluated after each iteration through the loop.
How the community answered
(37 responses)- A11% (4)
- B84% (31)
- D5% (2)
Explanation
B is correct because expr1 is indeed optional - you can omit it (e.g., for (; expr2; expr3)) - and when present, it runs exactly once before the loop begins, making both claims in B accurate. C is correct because expr2 acts as the loop's exit condition: when it evaluates to false, execution exits the loop, and it is re-evaluated after each iteration completes (before the next one starts).
A is wrong because the question treats this as the only valid for construct in the given language context - the enhanced for-each loop (for (Type var : collection)) is a separate construct, not an alternate "for loop constructor" in the same category. D is wrong because expr3 is not required - you can omit it just as you can omit expr1 or expr2; a bare for (;;) is a valid (infinite) loop - so the word "must" makes D false, even though the second half (evaluated after each iteration) is accurate.
Memory tip: Think of the three expressions as I-C-U - Initialize (optional, once), Check (terminates on false, every cycle), Update (optional, every cycle). Only the Check has a terminating effect; the other two are entirely optional.
Community Discussion
No community discussion yet for this question.