Page 123 - 2622_Delhi Police Public School_C-8
P. 123

A sequence is a succession of values bound together by a single name.

                               The while statement executes a set of statements repeatedly, until the logical expression evaluates
                            to true.
                              To come out of the infinite loop, we can either close the program window or press Ctrl + C.

                               The else block is executed when the condition given in the while statement becomes false.

                               The break is a keyword in Python which is used for bringing the program control out 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.



                                                   Assess Yourself



                        Choose the correct option.

                        1.  What is the use of range(n) function?

                                  a. Generates a set of whole numbers starting from 0 to (n+1).

                                  b. Generates a set of whole numbers starting from 1 to (n+1).

                                  c. Generates a set of whole numbers starting from 0 to (n-1).

                                  d. Generates a set of whole numbers starting from 1 to (n-1).


                        2.  Which of the following is a looping statement in Python?

                                  a. for statement                              b. continue statement

                                  c. if statement                               d. break statement

                        3.  Which of the following statements allow to repeat a task for a fixed number of times?

                                  a. for statement                              b. while statement

                                  c. if…else statement                          d. continue statement


                        4.  Which of the following statements terminates the execution of the loop?
                                  a. if                                         b. for


                                  c. break                                      d. continue


                        Tick ( ) the correct statements and cross ( ) the wrong ones.

                        1.   The range( ) function is used in the for loop to iterate over the numbers.

                        2.  The continue statement breaks the loops one by one.



                                                                                                 Loops in Python   121
   118   119   120   121   122   123   124   125   126   127   128