Pythonbreak statement details

Source: Internet
Author: User
This article mainly introduces the functions and usage of the Pythonbreak statement. if you need it, you can refer to the Python break statement, just like breaking the minimum closed for or while loop in the C language. The break statement is used to terminate a loop statement. that is, if the loop condition does not have the False condition or the sequence is not completely recursive, the execution of the loop statement is also stopped.
The break statement is used in the while and for loops. If you use nested loops, the break statement stops executing the deepest loop and starts executing the next line of code.

I. break statement syntax in Python

The code is as follows:

Break

II. logic flowchart

III. use instances

The code is as follows:

#! /Usr/bin/python

For letter in 'Python': # First Example
If letter = 'h ':
Break
Print 'current Letter: ', letter

Var = 10 # Second Example
While var> 0:
Print 'current variable value: ', var
Var = var-1
If var = 5:
Break

Print "Good bye! "


Execution result of the above instance:

The code is as follows:

Current Letter: P
Current Letter: y
Current Letter: t
Current variable value: 10
Current variable value: 9
Current variable value: 8
Current variable value: 7
Current variable value: 6
Good bye!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.