17 Aug Python break and continue statements
The break and continue statements are called Decision-Making Statements in Python. Let us understand them one by one:
break statement in Python
In the break statement, the current loop is terminated and the execution of the program is aborted. After termination, the control reaches the next line after the loop.
Syntax
1 2 3 |
break; |
Example – break statement
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# break statement in Python # Code by studyopedia mystr = "Studyopedia" print("String = ",mystr) for i in mystr: if i == 'p': break; print(i) |
The output is as follows:
1 2 3 4 5 6 7 8 9 |
String = Studyopedia S t u d y o |
continue statement in Python
The continue statement in Python transfers control to the conditional expression and jumps to the next iteration of the loop.
Syntax
1 2 3 |
continue; |
Example – continue statement
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# continue statement in Python # Code by studyopedia mystr = "Studyopedia" print("String = ",mystr) for i in mystr: if(i=='p'): continue; print(i) |
The output is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
String = Studyopedia S t u d y o e d i a |
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
No Comments