Page 102 - TP-Play_V-2.0_Book-8
P. 102

range(start, stop): Generates a set of whole numbers starting from ‘start’ to ‘stop–1’.
               Example: range(3, 9) is equivalent to [4, 5, 6, 7, 8].
                 range(start, stop, step_size): By default, the value of the step_size = 1 and numbers generated
               with a difference of 1. However, we can generate numbers by specifying the value of step_size
               according to our requirement.
               Example: range(1, 14, 2) is equivalent to [1, 3, 5, 7, 9,11,13].

            Program 3: To print your name nine times using for loop with range() function












            On running the above program, we get the following output:




















                THE WHILE STATEMENT

            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. The syntax of
            while statement is given below.

            Syntax:
            while (test expression):
                   Statements




                                                                        False
                                                       Test Expression



                                                              True

                                                     Execute while Block


                                                                      Exit loop



            102       Play (Ver. 2.0)-VIII
   97   98   99   100   101   102   103   104   105   106   107