Loop control statements
Loop control statements change execution from its normal sequence. Following are the loop control statements provided by Python:
- Break: Break statement in Python is used to bring the control out of the loop when some external condition is triggered.
- Continue: Continue statement is opposite to that of break statement, instead of terminating the loop, it forces to execute the next iteration of the loop.
- Pass: Pass statement is used to write empty loops. Pass is also used for empty control statement, function and classes.
# Python program to demonstrate
# break, continue and pass
s = 'w3wiki'
for letter in s:
if letter == 'e' or letter == 's':
break
print(letter, end = " ")
print()
for letter in s:
if letter == 'e' or letter == 's':
continue
print(letter, end = " ")
print()
for letter in s:
if letter == 'e' or letter == 's':
pass
print(letter, end = " ")
Output:
g
g k f o r g k
g e e k s f o r g e e k s
Note: For more information, refer break, continue and pass in Python.
How to Learn Python from Scratch in 2024
Python is a general-purpose high-level programming language and is widely used among the developers’ community. Python was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code.
If you are new to programming and want to learn Python Programming from Scratch, then this complete 2024 guide is here to help you. Whether you are an experienced programmer or new to the programming world, this guide will help you with the knowledge and resources needed to get started with Python Language.