python tutorial - Python Break - learn python - python programming




What is Python Break?

  • Python break statement, it terminates the current loop and resumes execution at the next statement, just like the traditional break statement in C.
  • The most common use for break is when some external condition is triggered requiring a hasty exit from a loop.
  • The break statement can be used in both while and for loops.
  •  python-break

    Learn Python - Python tutorial - python-break - Python examples - Python programs

  • Break statement is a jump statement that is used to pass the control to the end of the loop.
  • When break statement is applied the control points to the line following the body of the loop, hence applying break statement makes the loop to terminate and controls goes to next line pointing after loop body.
 python break statement

Example:

  • Use of break statement inside loop
for val in "string":
    if val == "i":
        break
    print(val)

print("The end")

Output:

s
t
r
The end
  • In this program, we iterate through the "string" sequence.
  • We check if the letter is "i", upon which we break from the loop.
  • Hence, we see in our output that all the letters up till "i" gets printed.
  • After that, the loop terminates.

Wikitechy tutorial site provides you all the learn python , online python course with certificate , python coding course , python scripting course python programming course online free

Related Searches to Python Break

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×