Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
3k views
in Blog Post by 48 54 93
edited by

In this post, we will explain the difference between the jumping statement break and continue in python.

break vs continue


Break-in Python

  • The break is a "jump out" statement that terminates the loop that containing the break statement and move the program control to the statement that is after the loop end depending on the condition.

If the Break statement in a nested loop then it terminates the nested loop to be back to the outer loop.

 Example:

Break statement in Loops

In the following example, we iterate through the "apple" string and the break statement will terminate the loop when x=l

for x in "apple":    
    if x== "l":
        break
    print(x)

The output will be

a
p
p

Continue Statement in Python

  • Continue is a statement that skips only the current iteration execution of the loop.
  • Continue statement is a control statement when it executed in the loop the program will skip the code that after continue and go bake to the next iteration of the loop.

Example:

In the following example, we iterate through the "apple" string and the continue statement will skip the code of the loop iteration when x=l only and continue the iteration of the loop to the end.

for x in "apple":
    if x == "l":
        continue
    print(x)

The output will be

a
p
p
e

Conclusion

In this post, we have explored the difference between break and continue statements in Python.

See Also


1.1k questions

673 answers

454 comments

193k users

تعلم بالعربي PowerApps

تعلم بالعربي Power Automate

If you don’t ask, the answer is always NO!
...