Java while loop example program

Java while loop example program

Java while statement continually executes a block of statements while a particular condition is true.

while statement structure


while(expression){
//statements
}




Example


public class WhileDemo {
public static void main(String[] args) {
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
}
}

output

-->