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.
Syntax:
while(condition){ //code to be executed }
su_row]
Program Example –
public class WhileExample { public static void main(String[] args) { int i=1; while(i<=10){ System.out.println(i); i++; } } }
2
3
4
5
6
7
8
9
10