Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Web -L04 (While Loop)

Snippet info

Language

Python

Visibility

public

Author

victormakwaitat

Created

2025-02-06T02:37:50.135329Z

Updated

2025-02-06T02:44:04.535353Z

x = 25
while x > 20 or print("x is larger than 20"):
    x -= 1 # In this case, same as break
else:
    print("when to run this line ?")

x = 25
while x > 20:
    print("x is larger than 20")
    if x == 23:
        break
    x -= 1 # In this case, same as break
else:
    print("when to run this line ?")
    
x = 25
while x > 20:
    if x == 23:
        break
    x -= 1
    if x == 24:
        continue
    print("x is larger than 20, now x is", x)
else:
    print("when to run this line ?")
    
x = 21
while x > 20:
    if x == 23:
        break
    x -= 1
    if x == 24:
        continue
    print("x is larger than 20, now x is", x)
else:
    print("normal exit or less than 20")
INFO