|
What is a Java while loop |
|
|
A Java while loop is a looping construct which continually executes a block of statements while a condition remains true.
The syntax of a while loop in Java is:
while (expression) {
statement
}
|
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
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.