Page 147 - TP_Prime_V2.2_Class8
P. 147

Program 8: To demonstrate the concept of infinite loop.

                     Program8.py
                  File  Edit  Format   Run    Options   Window    Help

                  a=13
                  x=1
                  while x>=1:
                      print(x*a)
                      x+=1




                     Output                                                                                                 LOOPS IN PYTHON
                  13
                  26
                  39
                  52
                  65
                                                                                                                          145
                  78
                  91
                  104
                  117
                  130



                                                              Infinit Loop

                 This loop will never end as there is no termination condition.
                                                                                                     21 st
                                                                                                   Century   #Critical Thinking
                                                                                                    Skills
                      Warm              What will be the output of the following Python code:
                      Up!               i = 0


                                        while (i == 0):

                                            print("Hello Touchpad")
                                        ___________________________________________________

                                        ___________________________________________________







                   Loop with else Statement


                 Similar to  'if', loops  can also  have  the  'else' statement. This  is  executed if the  loop

                 terminates normally. Both for and while loops can have else statement. The else statement
                 can be used with loops but it is not mandatory. Let us print the cube of all the numbers
                 between 0 and 12 with an else statement to understand it better.
   142   143   144   145   146   147   148   149   150   151   152