Page 340 - CITS - Computer Software Application -TT
P. 340
COMPUTER SOFTWARE APPLICATION - CITS
It is also known as the exit-controlled loop since the condition is not checked in advance. The syntax of the do-
while loop is given below.
do
{
//statements
} while (condition);
The flow chart of the do-while loop is given in the following image.
Consider the following example to understand the functioning of the do-while loop in Java.
Calculation.java
public class Calculation {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 0;
System.out.println(“Printing the list of first 10 even numbers \n”);
do {
System.out.println(i);
i = i + 2;
}while(i<=10);
}
}
Output:
Printing the list of first 10 even numbers
0
2
4
327
CITS : IT&ITES - Computer Software Application - Lesson 85 - 93