Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 119 - 2615_KEC
P. 119

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

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

                         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

                     The example above prints all the numbers except 8 because when the value of number is equal
                     to 8, the continue statement placed inside the if statement will force the program to skip the

                     iteration.

                     PROJECT: GREATEST NUMBER CHECKER

                     Software Used: CodeSkulptor
                     Objective:
                     Develop a Python program (WAP) to determine the greatest of three numbers using:

                         Arithmetic operators

                         Variables
                         Conditional statements (if, elif, else)
                         Formatted outputs
                     Use Codeskulptor3-https://py3.codeskulptor.org/

                     Step-by-Step Instructions: (Plan IPO)

                     1.  Input: The user enters three numbers (dynamic - varies with each user).

                                                                                            Control Structures in Python  117

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