What does while mean in python

silencement
Release: 2019-07-08 10:27:57
Original
22836 people have browsed it

What does while mean in python

In Python programming, the while statement is used to execute a program in a loop, that is, under certain conditions, execute a certain program in a loop to handle the same task that needs to be processed repeatedly. Its basic form is:

while Judgment statement:

Execution statement...

For example

a = 1
while a <= 10:
    print(a)
    a += 2
Copy after login

Output result

1
3
5
7
9
Copy after login

The meaning of this code is: the initial value of a is 1, and the judgment condition is: if a <10, then print a, Then add 2 to the returned a. If a<10, the program will be executed forever; if a is not less than 10, the program will be terminated. Obviously, the value of a returned for the fifth time is 9, 9 plus 2 equals 11, 11 is not less than 10, and the program terminates.

The above is the detailed content of What does while mean in python. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!