Python Jump Statements
Jump statements are used to skip, jump, or exit from the running program inside from the loop at the particular condition. They are used mainly to interrupt switch statements and loops. Jump statements are break, continue, return, and exit statement.
Jump Statements in Python
- Break Statement
- Continue Statement
- Pass Statement
Break statement
With the help of the break
the statement, we can terminate the loop. We can use it will terminate the loop if the condition is true. By the keyword we describe the break statement.
Example of break Statement
We are going to print a series, and we want to stop the loop after executing two time
x=1
while x<=10:
print(x)
if x==5:
break
x=x+1
print("This statement will print after the loop..")
1
2
3
4
5
This statement will print after the loop..
Note: The break statement only terminates the loop, it does not completely stop the flow of the program.
Python for loop – Continue statement
With the help of the continue statement, we can terminate any iteration and it returns the control to the beginning again. Suppose we want to skip/terminate further execution for a certain condition of the loop. By using the continue keyword we define the continued statement.
Example of continue Statement
We are going to print a series, and we want to skip the loop at the time when x is equal to 5.
x=0
while x<=10:
x=x+1
if x==5:
continue
print(x)
print("This statement will print after the loop..")
1
2
3
4
6
7
8
9
10
This statement will print after the loop..
Note: The continue statement only skip on an iteration of the loop, it does not completely stop the flow of the program. Therefore, the statements outside loops will still run if exists.
Exercises & Assignments |
---|
No Content Found. |
Interview Questions & Answers |
---|
No Content Found. |