Page 66 - Modular_V1.1_Flipbook
P. 66

cout<<”The factorial of “<< num<<” is “<<(double)fact;

                        getch();
                  }
                      Recap



                          The statements that are used to repeat a set of instructions are called iterative or looping
                         statements.

                         The for loop executes a simple or compound statements for a fixed number of times or until a
                         condition becomes false.
                         C++ allows you to combine two expressions using the comma operator.
                         The while loop executes a set of statements repeatedly until a certain condition is met.

                         The do-while loop is similar to the while loop.
                         If a loop executes inside another loop, it is known as nested loop.
                         The loop that never ends is called infinite loop.
                         The break statement in C++ is used to stop the execution of a program or part of a program.
                         The continue statement is used to skip the current iteration of the loop.
                         The goto statement is used to change the normal flow of program execution and transfer the
                         control to some other part of the program.





                                                         Exercise



                  A.   Tick (3) the correct option.
                       1.  Which of the following is a looping statement in C++?
                           a.  for statement                                c.  while statement

                           b.  do-while                                    d.  all of these
                       2.  Which of the following statements is correct about the while loop?
                           a.  Repeat a block of code a given number of times

                           b.  Repeat a block of code until a condition is true
                           c.  Repeat a block of code until a condition is false
                           d.  Repeat a block of code indefinitely

                       3.  Which of the following statements is used to repeat a task for a fixed number of times?
                           a.  for statement                                c.  while statement
                           b.  continue statement                          d.  break statement

                       4.  Which statement is used to transfer the control to a particular part of the program?
                           a.  goto                                         c.  while
                           b.  do-while                                    d.  break






                  64      Touchpad MODULAR (Version 1.1)-X
   61   62   63   64   65   66   67   68   69   70   71