Logo

dev-resources.site

for different kinds of informations.

Loop Control statements in Python : break, continue, pass

Published at
8/22/2024
Categories
python
loops
Author
debasmita-a
Categories
2 categories in total
python
open
loops
open
Author
11 person written this
debasmita-a
open
Loop Control statements in Python : break, continue, pass

In Python, we have 3 loop control statements : break, continue and pass.

break

When the condition satisfies, the loop breaks and comes out of the loop.

for i in range(10):
    print(i)
    if i == 5:
        break

# It will print : 0 to 5 and once the condition satisfies, 
# then the loop breaks.
Enter fullscreen mode Exit fullscreen mode

continue

When the condition satisfies, it is skipped and moves on to next iteration in the loop.

for i in range(10):
    if i == 5:
        continue
    print(i)

# It will print : 0 to 9 except 5.

Enter fullscreen mode Exit fullscreen mode
for i in range(10):
    if i != 5 :
        continue
    print(i)

# It will print just 5.
Enter fullscreen mode Exit fullscreen mode

pass

It does nothing. It acts as a placeholder.

for i in range(10):
    if i == 5:
        pass
    print(i)

# It will not do anything, even if the condition satisfies
Enter fullscreen mode Exit fullscreen mode
loops Article's
30 articles in total
Favicon
break, continue in Dart programming (Bangla)
Favicon
Python Day-22 String Functions logic using loops, Recursion, Tasks
Favicon
Comprehensive Guide to Loops in JavaScript
Favicon
For loops and comprehensions in Elixir - transforming imperative code
Favicon
Converting Loops into Recursion: Templates and Tail Recursion Explained
Favicon
Python Day-21 String functions logic using loops
Favicon
Python Day-20 String functions logic using loops,Task
Favicon
Still Don't Understand Loops? Look No Further.
Favicon
Basic Loops in Python
Favicon
MASTERING LOOPS IN JAVASCRIPT: A COMPREHENSIVE GUIDE
Favicon
Control Flow in Python: Loops, Break, Continue, and Pass Explained
Favicon
`for...in` vs. `for...of` in JavaScript:
Favicon
Async Loops in JavaScript: for...of vs forEach
Favicon
Loop Control statements in Python : break, continue, pass
Favicon
Mastering Terraform: How Loops and Conditionals Unlock Smarter Infrastructure Automation
Favicon
How to Reverse a String in JavaScript Using a For Loop
Favicon
Loops: For Loops, While Loops, For...Of Loops, For...In Loops
Favicon
Review: DetecciΓ³n de loops infinitos AWS lambda
Favicon
πŸŽ“ Mastering JavaScript Basics: Conditional Statements and Loops πŸ”„
Favicon
Optimization of Loops in JavaScript
Favicon
Python Flow Control Full Tutorial
Favicon
Exploring Different Looping Techniques in JavaScript πŸš€πŸ”„
Favicon
Scopes/ Loops/ break/ continue
Favicon
UNDERSTANDING MEMORY USAGE: INSIGHTS ON RECURSION AND DO WHILE LOOPS
Favicon
Brute Force way of Looping Combination
Favicon
Why Python Is Easier (Loops edition)
Favicon
Mastering Python iteration: Loops and the magic of list comprehensions
Favicon
Vocal Pop & Slap House Sample Loops Download
Favicon
Loops in C programming
Favicon
Mastering PHP Foreach Loops: The Power of '&' for References βš‘πŸš€

Featured ones: