Home > Backend Development > Python Tutorial > What does python break mean?

What does python break mean?

藏色散人
Release: 2019-06-21 11:59:30
Original
11754 people have browsed it

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)
Copy after login

Code effect:

i=1
i=2
i=3
i=4
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template