Co-Authored By:

Asked by: Jaymie Sieberkropp
technology and computing programming languagesWhat is while true in Java?
People also ask, what does true mean in Java?
A Boolean value is one with two choices: true or false, yes or no, 1 or 0. In Java, there is a variable type for Boolean values: boolean user = true; So instead of typing int or double or string, you just type boolean (with a lower case "b").
Similarly one may ask, is while true bad practice?
It is not a bad practice, it just means that you did not think your code through. The condition is required to tell the loop when to finish looping. Both methods are correct, but if someone else is reading your code, it is much easier to see when the loop will stop iterating if it is right there in the condition.
The while statement takes an expression and executes the loop body while the expression evaluates to (boolean) "true". True always evaluates to boolean "true" and thus executes the loop body indefinitely. It's an idiom that you'll just get used to eventually!