Username   Password       Register

Java While Loop

A Java while loop is a looping construct which continually executes a block of statements while a condition remains true.

Java while loop syntax

The syntax of a while loop in Java is:


while (expression) {
statement
}

Example Java while loop

Here is a Java while loop that prints the numbers 1 through 10.


int loopvar = 1; // Declare and initialize the loop counter
while (loopvar <= 10) { // Test and loop
System.out.println(loopvar); // Print the variable
loopvar = loopvar + 1; // Increment the loop counter
}
blog comments powered by Disqus

Discuss Java While Loop in the forums.

 
(0 - user rating)