Page 62 - Modular_V1.1_Flipbook
P. 62

The continue Statement

                  The  continue  statement  is  used  to  skip  the  current  iteration  of  the  loop.  When  a  continue
                  statement is encountered inside a loop, control of the program jumps to the beginning of the
                  loop  for  next  iteration, skipping  the  execution  of  rest  of  the  statements  of  the  loop  for  the
                  current iteration. The syntax of the continue statement is:
                  while(condition)
                  {
                        if(conditional expression)
                        {
                             continue;

                        }
                  }
                  Program 8: To display the numbers from 1 to 10 except the number 7.

                  #include<iostream.h>
                  #include<conio.h>                                                                 Output:
                  void main()                                                                       1
                  {                                                                                 2
                                                                                                    3
                        int num = 10;
                                                                                                    4
                        for(int i = 1; i <= num; i++)
                                                                                                    5
                             if(i==7)
                                                                                                    6
                                               continue;
                                                                                                    8
                             else                                                                   9
                                               cout<<i << “\n”;                                     10

                        cout<<”Out of the loop”;                                                    Out of the loop
                        getch();
                  }
                  In the preceding output, you can see that the number 7 is skipped because of the continue
                  statement.
                  The goto Statement


                  C++ provides another jump statement named goto. This statement is used to change the normal
                  flow of program execution and transfer the control to some other part of the program. The
                  syntax of goto statement is:
                  goto label;
                  ... .. ...

                  ... .. ...
                  label:
                  statement;
                  ... .. ...




                  60      Touchpad MODULAR (Version 1.1)-X
   57   58   59   60   61   62   63   64   65   66   67