Page 183 - Cs_withBlue_J_C11_Flipbook
P. 183

{
                            System.out.print(i*2);
                            }
                            System.out.println();
                    }
                 •  Nested while loop: The while loop inside another while loop is called a nested while loop.
                   For example:
                    int i=1, j;
                    while(i<=3)                                                             Output:
                    {                                                                           2
                        j=1;                                                                    3 4
                       while(j<=i)                                                              4 5 6
                       {
                            System.out.print((i+j)+ " ");
                            j++;
                       }
                       System.out.println();
                       i++;
                    }
                 •  Nested do-while loop: The do-while loop inside another do-while loop is called a nested do-while loop.
                   For example:

                    int i=3, j;
                                                                                            Output:
                    do
                                                                                                3
                    {
                        j=3;                                                                    2 2
                       do                                                                       1 1 1
                       {
                            System.out.print(i+" ");
                          j--;
                       } while(j>=i);
                        System.out.println();
                       i--;
                    } while(i>=1);
                 Jump Statement
                 Some statements transfer the program control from one part of the program to another part depending on a certain
                 condition. Such statements are called jump statements. They are also a type of control statements.
                 In Java, there are three jump statements which are as follows:
                 •  break: In Java, the break statement is used to exit from the loop or switch statement. The program pointer goes
                   to the line that follows the loop or switch statement. The statements after the break statement inside the loop or
                   switch will not be executed. It is used for an unusual termination of the loop. The break statement can be used with
                   all the different types of loops.
                   Syntax: using while loop
                    initialisation;
                    while(condition)
                    {
                        if(condition)
                            {

                                                                                                                       181
                                                                                                 Statements and Scope  181
   178   179   180   181   182   183   184   185   186   187   188