Page 339 - CITS - Computer Software Application -TT
P. 339
COMPUTER SOFTWARE APPLICATION - CITS
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”);
while(i<=10) {
System.out.println(i);
i = i + 2;
}
}
}
Output:
Printing the list of first 10 even numbers
0
2
4
6
8
10
Java do-while loop
The do-while loop checks the condition at the end of the loop after executing the loop statements. When the
number of iteration is not known and we have to execute the loop at least once, we can use do-while loop.
326
CITS : IT&ITES - Computer Software Application - Lesson 85 - 93