Python_break_and_continue
Python_break_and_continue
Contents
PYTHON TUTORIAL Python break and continue What is the use of break
and continue in Python?
Python Introduction In this article, you will learn to use break and continue statements to alter Python break statement
the ow of a loop.
Python Flow Control Syntax of break
-- Python Pass Loops iterate over a block of code until test expression is false, but Flowchart of continue
sometimes we wish to terminate the current iteration or even the whole loop Example: Python
-- Take Quiz
without checking test expression. continue
Python Functions The break and continue statements are used in these cases.
Python Datatypes
Python Files
Python Object & Class Python break statement
Python Advanced Topics The break statement terminates the loop containing it. Control of the program
Python Date and time ows to the statement immediately after the body of the loop.
If break statement is inside a nested loop (loop inside another loop), break
will terminate the innermost loop.
Syntax of break
break
Flowchart of break
The working of break statement in for loop and while loop is shown below.
RECOMMENDED READINGS
Run
Powered by DataCamp
Output
s
t
r
The end
Syntax of Continue
continue
Flowchart of continue
The working of continue statement in for and while loop is shown below.
Run
Powered by DataCamp
Output
s
t
r
n
g
The end
This program is same as the above example except the break statement has
been replaced with continue.
We continue with the loop, if the string is "i" , not executing the rest of the
block. Hence, we see in our output that all the letters except "i" gets
printed.
« PREVIOUS
PYTHON WHILE LOOP PYTHON PASS STATEMENT
NEXT
»
R Tutorials
Algorithms Tutorials