Categories: For ststementPython

for loop with continue,break,pass in Python

for loop with continue, break and pass in Python

In this tutorial, we will discuss the concept of for loop with continue, break and pass in Python.

for loop allows to repeat tasks in an efficient manner.
In python, pass, continue, and break statements can be used in for loops.

for loop with continue, break and pass

For with pass

We can use the pass statement to write empty loops. Pass is also used to empty control loops, function and classes. The pass statements is a null operation, nothing happens whilst it executes.

program 1

When the above code is executed, it produces the following results.
error

When the above code is executed, it produces the following results

No error and no output

 

When the above code is executed, it produces the following results

0
1
2
3
4
5
6
7
8
9

For with break

The break statement in python is used to terminate the execution of the current loop.

 

flow diagram for with break

program 1

When the above code is executed, it produces the following results.
error

program 2

 

When the above code is executed, it produces the following results.
No error and no output

program 3

When the above code is executed, it produces the following results.
0
program 4
When the above code is executed, it produces the following results.
No error and no output

Program 5

When the above code is executed, it produces the following results.
0
1
2
3
4

 

For  with continue

The continue statement is used in a loop to take the control to the top of the loop without executing the rest of the statements inside the loop.

flow diagram for with continue

program 1

When the above code is executed, it produces the following results.
error
Program 2
When the above code is executed, it produces the following results.
No error and no output

program 3

Example
When the above code is executed, it produces the following results.
0
1
2
3
4
6
7
8
9
Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.