Page 161 - CA_Blue( J )_Class10
P. 161
7 {
8 System.out.println(a);
9 a = a + 2;
10 } while(a >= 1);
11 }
12 }
• Null Loop/Delay Loop: A loop that has no code in its body is called a null loop or empty loop. This type of loop is
also known as delay loop as it delays the execution of the program. Using for null loop:
1 class null_for
2 {
3 public static void main()
4 { int i = 1;
5 for(i=1; i<=10; i++);
6 System.out.println(i);
7 } }
Since ending with ";", the loop does not include any statement in its body. So, it is a null loop. Using while loop:
1 class null_while
2 {
3 public static void main()
4 {
5 int a=-10;
6 while(a<=-1)
7 {
8 }
9 }
10 }
Since the loop does not have any statement in the body. So, it is a null loop. Using do-while loop:
1 class null_dowhile
2 {
3 public static void main()
4 {
5 int a=1;
6 do
7 {
159
Iterative constructs in Java 159

