Page 33 - Touchcode_C8_Flipbook
P. 33

At a Glance
                       Loops are programming elements which repeat a portion of code for a number of times till
                       the desired process is complete.

                       While, For and Nested are the different types of loops.
                       A looping condition must get false at a certain point of time, else the block of code will enter
                       in an infinite loop. For this it is important to define an exit criterion for the loop.






                      Exercise

                 A.  Tick ( ) the correct option.

                     1.  Which of the following loop executes a group of statements till a given condition is true?
                         a.  While                                    b.  For

                         c.  Nested                                   d.  If-else

                     2.  Which of the following loop repeat over a sequence?
                         a.  While                                    b.  For

                         c.  Nested                                   d.  If-else

                     3.  Which of the following loop contains another loop inside it?
                         a.  While                                    b.  For

                         c.  Nested                                   d.  If-else

                     4.  Which of the following describes the loop?
                         a.  save time

                         b.  minimize errors
                         c.  make the code more manageable

                         d.  All of the above

                     5.  Which of the following is the correct syntax to calculate the square of the number?
                         a.  sq= x + x                                b.  sq= x - x

                         c.  sq= x * x                                d.  sq= x % x

                 B.  State whether the following statements are true (T) or false (F).

                     1.  Loops do not repeat a portion of code.


                     2.   In nested loop once the condition is met then the loop gets terminated.




                                                                                       Get Creative with Loops   31
   28   29   30   31   32   33   34   35   36   37   38