Python while loop control flow statement structure and usage, pythonwhile

Source: Internet
Author: User

Python while loop control flow statement structure and usage, pythonwhile
What are the differences between the python while LOOP statement and the if statement?

To know the differences between the while statement and the if statement, you must first understand the working principle of the while statement.
If the condition is True, a corresponding code block is executed. while the code block in the while statement continues until the loop condition cannot be met and is no longer True.

Standard syntax for python while statements

The syntax of the while LOOP statement is as follows:
Python while condition:
Execution code block

The code block in the while loop is executed cyclically until the condition cannot be set to False. Then, the loop is exited and the statement following the loop body is executed. Python while LOOP statements are most often used in counting loops.

Python while loop control flow statement basic operation method

Let's take a simple example without any multiple conditions to see how the while loop control flow statements are used.
>>> X = 1
>>> While x <10:
>>> X + = 1
>>> Print x
2
3
4
5
6
7
8
9
10
When the initial value of variable x is 1 and the condition is that x is less than 10, the code block x + = 1 is executed until the value of x is no longer less than 10.

Similar to for statements, python while LOOP statements are often used together with break, continue, and else to meet the requirements of more conditions.

Play snake net article, reprint please indicate the source and source URL: http://www.iplaypython.com/jinjie/while.html

Q: customized IT education platform, one-to-one service, Q & A. Official Website for developing programming social headlines: www.wenaaa.com

QQ Group 290551701 has gathered many Internet elites, Technical Directors, architects, and project managers! Open-source technology research, welcome to the industry, Daniel and beginners interested in IT industry personnel!

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.