Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 119 - 2620_Birla Open Mind C-8
P. 119

    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 117

| 114 115 116 117 118 119 120 121 122 123 124 |