Java do while loops
Java do while loops is very similar to the while loops, but it always executes the code block at least once and further more as long as the condition remains true. This is exit-controlled loop.
The basic format of do while loop statement is:
Syntax:
do
{
statement(s);
}while( condition );
Figure – Flowchart of do while loop:
Example of a Java Program to Demonstrate do while loop
Example:
public class Sample {
public static void main(String args[]) {
/* local variable Initialization */
int n = 1, times = 0;
/* do-while loops execution */
do {
System.out.println("Java do while loops:" + n);
n++;
} while (n <= times);
}
}
Program Output:
0 comments:
Post a Comment