Page 146 - TP_Prime_V2.2_Class8
P. 146

Program 7: To print the table of 13 by using the while loop.

                      Program7.py

                   File  Edit  Format    Run   Options   Window    Help

                   a=13
                   x=1
           Prime (Ver. 2.2)-VIII      x+=1
                   while x<=10:
                       print(x*a)









                   13
                   26 Output
                   39
                   52
          144      65
                   78
                   91
                   104
                   117
                   130




                  Let us see how the while loop work:

                  Step 1:  Initialise the variable a with the value 13.

                  Step 2:  Initialise the variable x with the value 1.

                  Step 3: While the value of x does not reach 10.

                  Step 4:  Print the product of x and a for each iteration.

                  Step 5:  Increment the value of x by 1.

                  If the test condition in while statement is false, the loop body will never execute.

                   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.
   141   142   143   144   145   146   147   148   149   150   151