Sitemap
Bhavatharani

Bhavatharani

LOOP CONTROL STATEMENT IN PYTHON

2 min readMay 19, 2022

--

In Python, we have loop control statements that can be used to alter or control the flow of loop execution based on specified conditions. Python loop statements gives you a way execute the block of code repeatedly. But sometimes, you may want to exit a loop completely or skip specific part of a loop when it meets a specified condition. It can be done using loop control mechanism.

In Python we have following three types of loop control statements :

  • Break Statement
  • Continue Statement
  • Pass Statement
Press enter or click to view image in full size

Break statement:

Based on the given condition, the break statement stops the execution and brings the control out of the loop.

Example:

Get Bhavatharani’s stories in your inbox

Join Medium for free to get updates from this writer.

for val in “string”:
if val == “i”:
break
print(val)

Output

s
t
r
The end

Continue statement

The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.

Example:

for val in “string”:
if val == “i”:
continue
print(val)

Output:

s
t
r
n
g

Pass:

In Python programming, the pass statement is a null statement. The difference between a comment and a pass statement in Python is that while the interpreter ignores a comment entirely, pass is not ignored.

--

--