Loop Control Statements in C
Introduction to HTML
How to use the Github API
The image tag, anchor tag and the button tag
Ordered and Unordered Lists in HTML
The division tag
HTML Forms
Tables in HTML
Introduction to C Programming
Introduction to Python
Varibles and Datatypes in Python
Operators in Python
Typecasting in Python
Input and Output in Python
If Else in Python
Loops in Python
Break, Continue and Pass in Python
Python practice section 1
Lists in Python
Tuple in Python
Break, Continue and Pass in Python
Break and Continue are mainly used to control loops. Manytime we need to skip any specific iteration or
end loop when some specific condition arises, here we use break and continue.
Jump to specific section:
Break
Break keyword is used to break loops when any specific condition arises.
Example:
for i in range(10):
print(i)
if (i==5):
print("Break loop if i = 5")
break
Output:
0 1 2 3 4 5 Break loop if i = 5
Continue
Continue keyword is used to skip some iterations based on conditions.
Example:
for i in range(10):
if (i==5):
print("When i = 5, code below continue will not execute for current iteration")
continue
print(i)
Output:
0 1 2 3 4 When i = 5, code below continue will not execute for current iteration 6 7 8 9
Pass
In python we can not leave any block empty. If we need to leave any block empty then we use 'pass'
keyword.
Let us see what will happend if we leave block empty.
for i in range(10):
# this block is left empty, this line
# is not considered as code
# because this is comment
Output:
File "Now we will use pass keyword", line 4 # because this is comment ^ IndentationError: expected an indented block after 'for' statement on line 1
for i in range(10):
# this block is left empty, this line
# is not considered as code
# because this is comment
pass
Output:
Output is empty and no any error arise.