Page 99 - Trackpad_V2.1_class8
P. 99

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

                     Output

                  Count is: 1
                  Count is: 2
                  Count is: 3
                  Count is: 4







                           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 for exiting the program control out of the loop. The break statement
                 stops the execution of the loop and program flow continues to the statement after the loop. It is
                 mostly used when we need to exit a loop prematurely before the loop condition becomes false.
                 Program 9: To demonstrate the use of the break statement in a loop

                     Program9.py

                  File  Edit  Format   Run    Options   Window    Help

                  #Program to show the use of the break statement in the for loop

                  for number in range(0, 12):
                      if(number == 7):
                          break
                      print('Number is:', number)
                  print('Out of loop')



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

                     Output

                  Number is: 0
                  Number is: 1
                  Number is: 2
                  Number is: 3
                  Number is: 4
                  Number is: 5
                  Number is: 6
                  Out of loop










                                                                                        Control Structures in Python  97
   94   95   96   97   98   99   100   101   102   103   104