Page 203 - ComputerScience_Class_11
P. 203
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Enter a number: 121
121 is a palindrome number
Since the do-while loop executes at least once, we can term it an Exit Control Loop.
Different Terms Related to Loops
There are certain terms that are related to the loops. These terms are mentioned as follows:
1. Infinite Loop: A loop that never ends is called an Infinite Loop. It is also called Endless Loop.
For example:
for(i=10; i>=1; i++)
{
System.out.println(i);
}
Here, the program will print values 10, 11, 12, …… and so on and will never end.
Similarly, we can also use the while loop and do-while loop as an infinite loop.
2. Null Loop: A loop that does not contain any statement inside the body of the loop is called Null Loop. It is also called
Empty Loop as it has an empty loop body.
For example:
for(i=1; i<=100;i=i+1);
The above loop does not contain any statement and is terminated by a semicolon(;).
Similarly, we can also use while and do-while loops as a null loop.
3. Omitting Expression: In a loop, we can omit one or two parameters of the loop.
For example:
for(i=1; i<=10;)
{
System.out.println(i++);
}
Here, the step value (i.e., increment or decrement) is omitted.
4. Delay Loop: A delay loop is used to increase the time of the execution of the program. It pauses the execution of
the program for some finite amount of time. It has an empty loop body.
For example:
int i=1;
while(i<=1000)
{
i++;
}
Here, the while loop only increments the value of i to 1000 and does nothing else.
Statements and Scope 201

