Quick actions

cmd+k|ctrl+k

Navigation

Languages

3. flow block

Snippet info

Language

Python

Visibility

public

Author

aaron.lung.wai

Created

2022-11-23T14:18:04.180387Z

Updated

2024-04-06T03:31:59.299746Z

#while

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

print("loop ended")

#continue while

x = 0
while x < 5:
    x += 1
    if x == 3:
        continue
    print(x)
    
#break while

x = 1
while x < 5:
    if x == 3:
        break
    print(x)
    x += 1
    
#else while

x = 1
while x < 5:
    print(x)
    x += 1
else:
    print('While loop is a great tool')
    
#nested while

x = 1
while x < 10:
    print(x)
    while x < 3:
        print("We are at the very beginning")
    x += 1
else:
    print('While loop is a great tool')
INFO