RSS Feed

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
}  Java While Loop

Leave a Reply

Post your comments and questions below, but please follow our commenting guidelines.


Path: Home > Programming > Java > Java While Loop