Home » Java Programming » Flow Control

What will be the output of the program? int i = 0; while(1) { if(i == 4) { break; } ++i; } System.out.println("i = " + i);

Correct Answer: Compilation fails.

Explanation:

Compilation fails because the argument of the while loop, the condition, must be of primitive type boolean. In Java, 1 does not represent the true state of a boolean, rather it is seen as an integer.

← Previous Question Next Question→

More Questions from Flow Control

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion