In this tutorial, we will learn about the Python Loop Control Statements. Its types, and how to use them with the help of examples.

Python Loop control statements change execution from their normal sequence. When execution leaves a scope, all automatic objects that were create in that scope are destroy.

There are three types of Loops Control statement

  • Continue Statement
  • Break Statement
  • Pass Statement

Continue Statement

Continue statement is use in a loop to go back to the beginning of loop. This statement can be used in both while and for loops.

Syntax

continue
Syntax Continue Statement

Flow Diagram of Continue Statement in Python

Flow diagram Continue Statement in Python
Flow Diagram of Continue Statement in Python

Example of Python continue Statement with for Loop

#continue for loop
for i in range(10):
    if i == 5:
        continue
    print(i)
Continue Statement with for Loop

Let’s run the code

Example of Python continue Statement with for Loop
Example of Python continue Statement with for Loop

Example Python continue Statement with while Loop

#continue while loop
num = 3

while num < 15:
    num += 1
    
    if (num % 2) ==0:
        continue

    print(num)
Continue Statement with while Loop

Let’s run the code

Example Python continue Statement with while Loop
Continue Statement with while Loop

Break Statement

The most common use for break is when some external condition is triggered requiring a hasty exit from a loop. Break statement is use to jump out of loop to process the next statement in the program. This statement can be use in both while and for loops.

Syntax

break
Syntax of Break Statement in Python

Flow Diagram of Break Statement in Python

Flow Diagram of Break Statement in Python
Flow Diagram of Break Statement in Python

The Example of Python break Statement with for Loop

for i in range(10):
    if i == 5:
        break
    print(i)
Python break Statement with for Loop

Let’s run the code

Example of Python break Statement with for Loop
Example of Python break Statement with for Loop

The Example of Python break Statement with while Loop

i = 1

while i <= 20:
    print('9 * ',(i), '=',9 * i)

    if i >= 10:
        break
    
    i = i + 1
Example of Python break Statement with while Loop

Let’s run the code

Example of Python break Statement with while Loop
Example of Python break Statement with while Loop

Pass Statement

The statement is a null statement.

Syntax

pass
Syntax of Pass Statement

Example of Pass Statement in Python

for char in 'basicengineer':
    if (char == 'e'):
        pass
    print("current character: ",char)
Example of Pass Statement in Python

Let’s run the code

Example of Pass Statement in Python
Example of Pass Statement in Python

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about Python Wikipedia please click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *