GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python Break Statement - GeeksforGeeks Python Break StatementLast Updated : 5 Jun, 2026 The break statement in Python is used to immediately terminate a for or while loop when a specified condition is met. After the loop exits, program execution continues with the next statement following the loop. Example: Let's start with an example to understand how break works in a loop.
Output Found at 7! Explanation:
Let's understand the break statement with a loop using a flowchart: ![]() Break Statement with for LoopA for loop in Python iterates over a sequence (like a list, tuple, string or range) and executes a block of code for each item in that sequence. The break statement can be used within a for loop to exit the loop before it has iterated over all items, based on a specified condition.
Output 0 1 2 3 4 5 6 Break Statement with while LoopA while loop in Python repeatedly executes a block of code as long as a specified condition is True. The break statement can be used within a while loop to exit the loop based on dynamic conditions that may not be known beforehand.
Output 5 4 3 2 1 Countdown finished! Using break in Nested LoopsNested loops are loops within loops, allowing for more complex iterations, such as iterating over multi-dimensional data structures. When using the break statement within nested loops, it's essential to understand its scope:
Example: If we have a list of lists (a 2D list) and we want to find a specific number. Once we find the number, we want to stop searching in both the inner and outer loops.
Output 5 found! Explanation:
Loops in Python help automate repetitive tasks, but sometimes you may need to exit a loop, skip an iteration, or alter the normal flow of execution. These actions are handled using loop control statements. Python supports the following control/jump statements:
Related ArticlesComment Explore |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |