Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 87 - 2611_SmartGPT Pro V(5.0) C-8
P. 87

    THE CONTINUE STATEMENT
                     The continue statement is used inside loops. When a continue statement is encountered inside a

                     loop, control of the program jumps to the beginning of the loop for the next iteration, skipping the
                     execution of the rest of the statements inside the loop for the current iteration.
                     Syntax:

                          continue

                     Program 9: To print first 12 whole numbers except 8.

                         Program9.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 executing the above program, 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
                      Number is: 7
                      Number is: 9
                      Number is: 10
                      Number is: 11
                      Out of loop

                             uiz   Bee        What will be the output of the given Python code?
                                              _____________________________________________________________

                                                                                                      Loops in Python  85

| 82 83 84 85 86 87 88 89 90 91 92 |