|
A Java do loop is similar to the Java while loop, except that the while test happens at the bottom of the loop. This means that the loop always executes at least once.
The syntax of a do loop in Java is:
do {
statement(s)
} while (expression);
|
Here is a Java do loop that prints the number 1 -- even though the test fails.
int loopvar = 1; // Declare and initialize the loop counter
do {
System.out.println(loopvar); // Print the variable
loopvar = loopvar + 1; // Increment the loop counter
} while (loopvar >= 10); // Test and loop
|
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.