Home  >  Article  >  Backend Development  >  What does python break mean?

What does python break mean?

藏色散人
藏色散人Original
2019-06-21 11:59:3011678browse

What does python break mean?

What does python break mean?

break in python means to end the loop.

Example:

i = 0
while i<10:
    i+=1
    if i==5:  #当i=5时,结束整个循环
        break
    print("i=%d"%i)

Code effect:

i=1
i=2
i=3
i=4

Python break statement, just like in C language, breaks the minimum closed for or while loop .

The break statement is used to terminate the loop statement. That is, if the loop condition does not have a False condition or the sequence has not been completely recursed, the execution of the loop statement will also be stopped.

The break statement is used in while and for loops.

If you use nested loops, the break statement will stop execution of the deepest loop and start execution of the next line of code.

Related recommendations: "Python Tutorial"

The above is the detailed content of What does python break mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn