Page 198 - CA_Blue( J )_Class9
P. 198
Program 2 Print the squares of the first 5 multiple of 4.
1 class for_square
2 {
3 public static void main()
4 {
5
6 for (int i=4; i<=20; i=i+4)
7 {
8 System.out.println("Square of "+i+ " is : "+ (i*i));
9 }
10 }
11 }
You will get the following output:
Dry Run & Output
Step Number i Result(i*i)
1 4 16
2 8 64
3 12 144
4 16 256
5 20 400
Start
In a for loop, the condition is checked before the execution of the loop
body. Hence, we can call it the "Entry Control Loop”.
9.2.3 The while loop Test false
Expression
Java while loop is used to execute a set of statements repeatedly if the
number of iterations is not known. True
The syntax of the while loop is:
Body of while loop
initialization;
while (condition for testing)
{
Stop
196 Touchpad Computer Applications-IX

