Page 192 - Computer science 868 Class 12
P. 192
For example:
int i, j;
for(i=1; i<=4; i++)
{
j=i;
while(j<=4)
{
System.out.print(j);
j++;
}
System.out.println();
}
Output:
1234
234
34
4
f. Fixed Iterative loop: The loop which executes the body of the loop a fixed number of times is called a fixed iterative
loop. The number of iterations is known or fixed in this loop.
For example:
for(int i=1; i<=10; i=i+1)
{
System.out.println(i);
}
g. Unfixed Iterative loop: The while and do-while loops are known as unfixed iterative type loops as the increment or
decrement does not lie in front of the loop.
For example,
int i=1, n;
System.out.println("Enter a number ");
n=sc.nextInt();
do
{
i=i+1;
}while(i<=n);
Some applications of for loop
a. Omitting Expression: A ‘for loop’ contains three types of statements, i.e., initialisation, condition and step value.
Now we can omit certain expressions from the loop.
For example,
int i;
for(i=1; i<=10;) // The increment value is not written
{
Statements….
}
b. Including more expressions in for loop: We can add more than one expression, initialisation or step value within a
for loop.
For example,
for(var1=1, var2=10; var1<=var2; var1++,var2--)
{
System.out.println(var1+ " " + var2);
}
190190 Touchpad Computer Science-XII

