Page 105 - TP_Play_V2.2_Class8
P. 105

Double Tap                                                Century   #Information Literacy
                                                                                      21 st
                                                                                      Skills
                        1.  Write the syntax of for loop.


                        2.  Write the syntax of while loop.



                        3.  Write the output of the following:
                           a.  for num in range(-10, 0, 1):

                                print(num)


                           b.  count = 0
                             while (count < 5):
                                count = count + 1
                                print("Orange Education")




                      INFINITE LOOP


                 If the condition  given  in a loop never becomes false, then  the loop will  never terminate and run
                 indefinitely. This type of loop is called an infinite loop.

                 Example:

                 while(1)
                     print(“Hello”)
                 Output: Hello will be printed infinite times.

                 To come out of the infinite loop, we can either close the program window or press Ctrl + C. This will
                 break the running of the program. In fact, at any time during the execution of a program in Python, you
                 can press the key combination Ctrl + C to stop running the program.


                      JUMP STATEMENTS


                 Sometimes, there is a situation when the control of the program needs to be transferred out of the
                 loop body, even if all the values of the iterations of the loop have not been completed. For this purpose,
                 jumping statements are used in Python. They allow you to skip ahead, break out of loops, or terminate
                 the program entirely based on certain conditions. Python offers two jumping statements—break and
                 continue, which are used within the loop.










                                                                                                   #Loops in Python 103
   100   101   102   103   104   105   106   107   108   109   110