Page 110 - modular4.0
P. 110

Chapter Profile

                   Program 7: To demonstrate the use of the break statement in a loop.

                      Program7.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')



                  You will 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



                  The continue Statement
                  The continue statement is used inside loop. When a continue statement is encountered inside
                  a loop, control of the program jumps to the beginning of the loop for next iteration, skipping the
                  execution of rest of the statements in the loop for the current iteration.

                  The syntax of the continue statement:
                  #loop statements
                       continue
                  #the code to be skipped

                   Program 8: To demonstrate the use of the continue statement in a loop.

                      Program8.py

                   File  Edit  Format   Run    Options   Window    Help

                   #Program to show the use of the continue statement
                   for number in range(0, 12):
                       if(number == 8):
                           continue
                       print('Number is:', number)
                   print('Out of loop')






                108  Modular (Ver. 4.0)-VIII
   105   106   107   108   109   110   111   112   113   114   115