Quick actions

cmd+k|ctrl+k

Navigation

Languages

#7 While loop & controller

Snippet info

Language

Python

Visibility

public

Author

heungchingyu

Created

2025-08-15T11:32:48.577764Z

Updated

2025-08-15T12:40:01.019655Z

# for repeatnig time is determined
# while() - repeating time is unknown
#case 1 : controller inside while loop
x= 1
while (True):
    print(x)
    x=x+1
    #add a controller (continue / break) or it will loop indefinitely
    if (x==3):
        print(x)
        continue
        x=x+1
    if (x==7):
        break
else:
    print("loop exit normally")

#case 2: controller at while condition expression
    while (x < 10):
        print("second while loop",x)
    else:
        print("second loop exit normally")
INFO