Page 69 - Modular_V2.0_C++_Flikpbook
P. 69

clrscr();

                                                                                DOSBox 0.74, Cpu speed: max 100% cycles,
                     for(int i = 1; i <= num; i++)                          1
                     {                                                      2
                         if(i == 7)                                         3
                                                                            4
                             continue;
                                                                            5
                         cout<< i << "\n";
                                                                            6
                     }
                                                                            8
                     cout<< "Out of the loop";                              9
                     getch();                                               10
                 }                                                          Out of the loop

                 In the above 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 by transferring control to a specific location in the program. The
                 syntax of goto statement is:

                      goto label;
                      ... .. ...
                      ... .. ...

                      label:
                      statement;
                      ... .. ...
                 In the above syntax, you can see that a label is used with the goto statement to specify the

                 location where the control of the program execution will be transferred. At some other part of
                 the program, the same label will be available with colon (:).
                 Return Statement

                 The return statement is a jump statement used to exit from a function and pass control back to
                 the calling function. It may also return a value to the caller if the function is designed to return

                 one.
                 Syntax:

                 return;          // used in void functions (no value returned)
                 return value;    // used in functions that return a value
                 For example:

                 int add(int a, int b)
                 {
                     return a + b;  // returns the sum of a and b

                 }

                                                                                                                  67
                                                                                                         Loops
   64   65   66   67   68   69   70   71   72   73   74