Page 112 - Trackpad_V1_Book 8_Flipbook
P. 112

THE while LOOP
                  The while loop repeats a block of statements a given number of times until the control condition is

                  false. In this looping construct, first, the condition is checked and if it is true, the control will move
                  inside the loop and execute the statements until the condition becomes false. If the initial condition
                  is false then the control will not enter the loop block. The syntax of the while loop is as follows:
                  while(loop - condition):

                      statement(s)
                  Program 7: To add first five natural numbers















                  You will get the following output:




















                            JUMP STATEMENTS

                  These statements are used to jump out of the loop iterations even if the condition has not become
                  false. They alter the flow of control unconditionally. The jump statements defined in Python are
                  break and continue.
                  THE break STATEMENT
                  The break statement is used in the for and while loops to terminate the loop and completely
                  transfer the control from the loop to the next statement after the body of the loop. It is mostly used
                  when we need to exit from a loop at times.

                  Program 8: To demonstrate the use of the break statement














                  110   Trackpad (Version 1.0)-VIII
   107   108   109   110   111   112   113   114   115   116   117