In Python, we can change the flow of a loop using the control statements:
continue
break
pass
The continue
statement stops the current iteration and goes to the next.
for n in range(0, 5): if n == 2: continue print(n)
The break
statement breaks out of the innermost enclosing for
or while
loop.
for n in range(0, 5): if n == 2: break print(n)
The pass
statement does nothing, and is essentially a null statement. For example, it can be used in an if
statement to skip the current iteration. It can also be used as a placeholder for future code.
for n in range(0, 5): if n == 2: pass else: print(n)
RELATED TAGS
CONTRIBUTOR
View all Courses