Page 205 - CA_Blue( J )_Class10
P. 205

8              if(i%2==0)
                   9                  continue;

                  10              System.out.println();
                  11          }

                  12      }
                  13  }

                 Output:       1:
                               1:2:1:2:3:
                               1:2:3:4:1:2:3:4:5:

                 Explanation: When the value of “i” is an even number, the condition becomes true and the continue statement
                 executes, and the control goes to the next iteration of the outer loop. Hence, the statement System.out.println() does
                 not execute.


                 9.5.2 Using the continue Statement in the Inner Loop
                 To use the continue statement in the inner loop, the continue statement should be written in the body of the inner
                 loop as shown in the following code:

                   1  class innercontinue
                   2  {

                   3      public static void main()
                   4      {   int i ,j;

                   5          for(i=1;i<=5;i++)
                   6          {   for(j=1;j<=i;j++)

                   7              {       if(j%2==0)
                   8                          continue;

                   9                  System.out.print(j+":");
                  10              }

                  11              System.out.println();
                  12          }

                  13      }
                  14  }
                 Output:       1:

                               1:
                               1:3:
                               1:3:

                               1:3:5:
                 Explanation: When the value of “j” is an even number, the condition becomes true and the continue statement
                 executes, and the control goes to the next iteration of the inner loop without executing the statement System.out.
                 print(j+ “:”).

                                                                                                                       203
                                                                                                         Nested Loop   203
   200   201   202   203   204   205   206   207   208   209   210