While Loop In Java

Java While Loop ?

while loop checks whether the condition written in ( ) is true or not. If the condition is true, the statements written in the body of the while loop i.e., inside the braces { } are executed. Then again the condition is checked, and if found true, again the statements in the body of the while loop are executed. This process continues until the condition becomes false.

While loop is a most basic loop in C++. while loop has one control condition, and executes as long the condition is true. The condition of the loop is tested before the body of the loop is executed, hence it is called an entry-controlled loop.

Syntax :

      While (condition)

Example 1:

Output :

 Enter an integer : 7
 You have entered : 7
 Enter an integer : -2

 You have entered :-2
 Enter an integer : 9546
 You have entered : 9546
 Enter an integer : 0
 out of loop

Example 2:

Output :