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!