Java While Loop Control Statement with Program Example

In this java programming tutorial post, we will study and understand the working of Java While Loop Control Statement which is a looping control statement. We will also see a program example to understand the practical working of the While loop in java.

While Loop

The Java while loop is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use while loop. Usually while loop is used to when we don’t know how many times do we need to iterate the loop in advanced or the number of iterations is based on some condition.

Java While Loop flow diagram

Syntax:
while(condition){  
//code to be executed  
}

su_row]

Program Example –
[/su_row]
public class WhileExample {  
public static void main(String[] args) {  
    int i=1;  
    while(i<=10){  
        System.out.println(i);  
    i++;  
    }  
}  
}
Output
1
2
3
4
5
6
7
8
9
10
Watch it on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *