Page 107 - TP_Play_V2.2_Class8
P. 107

The Continue Statement

                 The continue statement is used inside loops. The continue statement skips the current iteration of a loop
                 and jumps to the beginning of the next iteration. It means 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 of the loop for the current iteration.

                 Syntax:
                 #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')




                 On running the 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
                  Number is: 7
                  Number is: 9
                  Number is: 10
                  Number is: 11
                  Out of loop

















                                                                                                   #Loops in Python 105
   102   103   104   105   106   107   108   109   110   111   112