Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python3
communitycreator

What are loop control statements in Python?

Dario Vincenzo Tarantini

In Python, we can change the flow of a loop using the control statements:

  • continue
  • break
  • pass

continue

The continue statement stops the current iteration and goes to the next.

for n in range(0, 5):
  if n == 2:
    continue
  print(n)

break

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)

pass

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

python3
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini
RELATED COURSES

View all Courses

Keep Exploring