The while loop in Java is a control flow statement that, if a given condition is met, continually runs a block of code.
Syntax :
while(condition){
// statements
}
First, while loop condition will tested. If the condition is true then the loop body code will be executed and again test the condition then again execute the loop body code. This process is repeated until the condition is false.
Flow Chart:
Example:
/*** Java While Loop Example*/public class JavaExample {public static void main(String[] args) {int i = 1;while (i<=5) {System.out.println(" While Loop Work Here : " +i);i++;}}}
Output:
While Loop Work Here : 1While Loop Work Here : 2While Loop Work Here : 3While Loop Work Here : 4While Loop Work Here : 5