Page 82 - Code Craft Computer-8
P. 82

¨  The for statement executes a simple or compound statement for a fixed number of times.

                    ¨  The 'in' operator is used to check if a given value exists in the sequence or not. It evaluates to
                       True if it finds a value in the specified sequence else it returns False.

                    ¨  The range() function is an in-built function of Python. This function generates a list which is a
                       sequence type. A sequence is a succession of values bound together by a single name. The
                       range() function is used in the for loop to iterate over the numbers.
                    ¨  The while statement executes a set of statements repeatedly, until the logical expression
                       evaluates to true. When the condition becomes false, the control comes out of the loop.
                    ¨  If the condition given in a loop never becomes false, then the loop will never terminate and run
                       indefinitely. This type of loops is called an infinite loop.
                    ¨  The break is a keyword in Python which is used for bringing the program control out of the
                       loop. The break statement halts the execution of a loop and program flow switches to the
                       statement after the loop.
                    ¨  The continue statement is used inside loops. 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.





                      Knowledge Check



              A.     Mark the correct response.
                     1.  The __________ statement allows to repeat a task for a fixed           OMR Sheet
                          number of times.                                                     Use only blue/black ball
                                                                                               pen to fill the circles. It
                          a. for                          b. while                             should   be   darkened
                                                                                               completely and properly.
                          c. Both a and b                 d. None of these
                                                                                               Wrong methods
                     2.   The  __________  statements  terminates  the  execution  of  the
                                                                                               Correct method
                          loop.
                          a. Break                        b. Continue
                                                                                               1.   a   b    c    d
                          c. For                          d. While
                     3.   Python offers __________ jumping statements.
                                                                                               2.   a   b    c    d
                          a. Two                          b. Three
                          c. Four                         d. Five                              3.   a   b    c    d

                     4.   To come out of the infinite loop, we can either close the program
                          window or press __________.                                          4.   a   b    c    d
                          a. Alt + C                      b. Ctrl + C
                                                                                               5.   a   b    c    d
                          c. Shift +C                     d. Alt + Ctrl + C

                     5.   The continue statement is used __________ loops.
                          a. Inside                       b. Outside
                          c. Both a and b                 d. None of these



                                                                 82
   77   78   79   80   81   82   83   84   85   86   87