nerdexam
Oracle

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.

Using Loop Constructs

Question

Given:

What is the result?

Exhibit

1Z0-803 question #209 exhibit

Options

  • A1
  • B1
  • C2
  • DCompilation fails
  • EThe loop executes infinite times

How the community answered

(61 responses)
  • A
    3% (2)
  • B
    18% (11)
  • C
    2% (1)
  • D
    7% (4)
  • E
    70% (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.

A1

This option implies a specific numerical output after loop termination, which would not occur in an infinite loop.

B1

This option implies a specific numerical output after loop termination, which would not occur in an infinite loop.

C2

This option implies a specific numerical output after loop termination, which would not occur in an infinite loop.

DCompilation fails

Infinite loops are runtime issues, not compilation failures; the code is syntactically valid and compiles successfully.

EThe loop executes infinite timesCorrect

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

#while loop#infinite loop#loop control

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice