While Loop In Java | Java Tutorial
In the last tutorial, we learnt for loop and enhanced for loop and in this tutorial we will discuss while loop.
The while statement continually executes a block of statements while a particular condition is true.
Syntax:
while (expression) { // statement(s) }
If the expression of while statement evaluates to true, then it executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false.
Sample Program:
package ClassThreeControlFlowStatements; public class WhileLoop { public static void main(String[] args) { int i = 1; while (i<=10){ System.out.println("Value of i is "+i); i++; } } }
Must Read: Java Tutorial