Break Continue Pass
Break Continue Pass
In Python, break and continue statements can alter the flow of a normal loop.
Loops iterate over a block of code until test expression is false, but sometimes we wish to terminate
the current iteration or even the whole loop without checking test expression. The break and
continue statements are used in these cases.
Python break statement
The break statement terminates the loop containing it. Control of the program flows 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.
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.
i=0 1
while i < 6: 2
i += 1 4
if i == 3: 5
continue 6
print(i)
Python pass statement
However, nothing happens when pass is executed. It results into no operation (NOP) or it says the
interpreter to do nothing.
Syntax of pass
pass
Suppose we have a loop or a function or an if-elif statement that is not implemented yet, but we
want to implement it in the future. They cannot have an empty body. The interpreter would
complain. So, we use the pass statement to construct a body that does nothing.