Page 191 - Computer science 868 Class 12
P. 191

Let us see this in detail.
                 a.  Delay loop: This loop is used to give a pause to the execution of the program for a specific period of time.
                   For example in the for loop:

                    for(long variable=0; variable<=100000000; variable+=1);
                 b.  Null/Body less/Empty loop: Any loop that does not include any statement in the body of the loop is called a null,
                   body less or an empty loop.
                   For example in the while loop:
                    int i=1;
                    while(i<=1000)
                    {
                        i++;
                    }
                 c.  Infinite/Endless loop: This loop executes endlessly because the terminating condition does not satisfy.

                   For example in the do while loop:
                    int var1=1;
                    do
                    {
                        System.out.println(i);
                    }while(var1<10);
                 d.  Finite loop: The loop which executes the body of the loop before the condition is met and the control knows when
                   the loop ends, is known as a finite loop.
                   For example in the while loop:
                    int var1=1;
                    while(var1<=10)
                    {
                        System.out.println(var1);
                        var1=var1+1;
                    }
                   The above program ends when the variable var1 is 11. The variable var1 increases by 1 after each iteration.
                 e.  Nested loop: When a loop exists inside another loop, then it is called a nested loop. We can use any type of loop to
                   apply the logic of a nested loop.
                   For example in the for loop:

                    int i, j;
                    for(i=1; i<=4; i++)
                    {
                        for(j=1; j<=2; j++)
                        {
                            System.out.print(j);
                        }
                            System.out.println();
                    }
                   Output:
                   12
                   12
                   12
                   12


                         Note: We can use two different types of loops in a nested loop.





                                                                                                                       189
                                                                                                 Statements and Scope  189
   186   187   188   189   190   191   192   193   194   195   196