VOOZH about

URL: https://www.geeksforgeeks.org/python/loops-and-control-statements-continue-break-and-pass-in-python/

⇱ Loops and Control Statements in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Loops and Control Statements in Python

Last Updated : 10 Mar, 2026

Python supports two types of loops: for loops and while loops. Alongside these loops, Python provides control statements like continue, break, and pass to manage the flow of the loops efficiently. This article will explore these concepts in detail.

for Loops

A for loop in Python is used to iterate over a sequence (such as a list, tuple, string, or range).


Output
1
2
3

while Loops

A while loop in Python repeatedly executes a block of code as long as a given condition is True.


Output
0
1
2
3
4

Control Statements in Loops

Control statements modify the loop's execution flow. Python provides three primary control statements: continue, break, and pass.

1. break Statement

The break statement is used to exit the loop prematurely when a certain condition is met.


Output
0
1
2
3
4

Explanation:

  • The loop is supposed to run 10 times (from 0 to 9).
  • When i equals 5, the break statement exits the loop.

2. continue Statement

The continue statement skips the current iteration and proceeds to the next iteration of the loop.


Output
1
3
5
7
9

Explanation:

  • The loop prints odd numbers from 0 to 9.
  • When i is even, the continue statement skips the current iteration.

3. pass Statement

The pass statement is a null operation; it does nothing when executed. It's useful as a placeholder for code that you plan to write in the future.


Output
0
1
2
3
4

Explanation:

  • The pass statement does nothing and allows the loop to continue executing.
  • It is often used as a placeholder for future code.

Exercise: How to print a list in reverse order (from last to the first item) using while and for-in loops.

Comment
Article Tags:
Article Tags: