Page 245 - CA_Blue( J )_Class9
P. 245

11              }
                  12          }

                  13      }
                 You will get the following output:





















                 In the above program, when the value of ‘i’ is 3, the condition is true and the break statement is executed which
                 results in the control coming out of the inner loop and the next iteration of ‘i’ initiates.


                     10.5 USING CONTINUE STATEMENT IN NESTED LOOP
                 Same as the break statement, continue can also be used in a nested loop. But, the continue statement works the
                 opposite to the break statement. As soon as a continue statement is executed, the rest of the statements in the
                 loop will be skipped and the control will proceed to the next iteration, i.e., the increment or decrement part of the
                 loop. By placing the continue statement in the correct position, the control will execute either the next iteration of
                 the inner loop or the outer loop.



                  Program 6      Using continue statement in the Outer Loop.

                   1      class outerloop_continue

                   2      {
                   3          public static void main()

                   4          {   int i ,j;
                   5              for(i=5;i>=1;i=i-1)

                   6              {   for(j=1;j<=i;j++)
                   7                  {         System.out.print(j);  }

                   8                  if(i==3)
                   9                      continue;

                  10                  System.out.println();
                  11              }

                  12          }
                  13      }



                                                                                                   Nested Loop   243
   240   241   242   243   244   245   246   247   248   249   250