python learning, while

python while loop structure

1
2
3
4
5
count = 0

while count <10:
   print(count)
   count = count + 1

Save as helloworld.py and execute the result

1
2
3
4
5
6
7
8
9
10
11
[me@VM_0_14_centos python] # python helloworld.py
0
1
2
3
4
5
6
7
8
9

In the above code
Line 1 creates a variable count and initializes it to 0

Line 2 starts the while loop structure, and first determines whether the statement after the while is True, True continues to execute the while statement, and False exits

Line 3 prints the current count value

Line 4 first calculates count + 1 to get a new value, and re-assigns to count, which can generally be understood as incrementing by +1

Persist in original technology sharing, your support will encourage me to continue to create!