1Z0-803 · Question #209
Given: What is the result?
The correct answer is E. The loop executes infinite times. The given code fragment contains a loop with a condition that ensures it runs indefinitely, and the break statement intended to terminate the loop is enclosed within an if condition that is never met.
Question
Given:
What is the result?
Exhibit
Options
- A1
- B1
- C2
- DCompilation fails
- EThe loop executes infinite times
How the community answered
(61 responses)- A3% (2)
- B18% (11)
- C2% (1)
- D7% (4)
- E70% (43)
Why each option
The given code fragment contains a loop with a condition that ensures it runs indefinitely, and the `break` statement intended to terminate the loop is enclosed within an `if` condition that is never met.
This option implies a specific numerical output after loop termination, which would not occur in an infinite loop.
This option implies a specific numerical output after loop termination, which would not occur in an infinite loop.
This option implies a specific numerical output after loop termination, which would not occur in an infinite loop.
Infinite loops are runtime issues, not compilation failures; the code is syntactically valid and compiles successfully.
The loop's primary condition, typically `while(true)` or an equivalent, ensures it would run indefinitely. A `break` statement that could terminate the loop is present, but it is contained within an `if` block whose condition is never satisfied, preventing the `break` from being executed and leading to an infinite loop.
Concept tested: Java loop control flow and termination conditions
Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
Topics
Community Discussion
No community discussion yet for this question.
