[Python] Study Notes 7——While

Insert picture description here

while

The while True condition makes it impossible to exit the loop unless it encounters a break statement.
If you fall into an infinite loop, use ctrl + c on your computer to force termination

count=0

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

result:
Insert picture description here

break

count=0

while count<=5:
    if count==3:
        break
    print(count)
    count=count+1

Result:
Insert picture description here
Range is useful when knowing how many times to loop

count=list(range(1,5))
print(count)
while len(count)>0:
    first=count[0]
    count.remove(first)
    print(count)

result:
Insert picture description here

Guess you like

Origin blog.csdn.net/Shadownow/article/details/105846083