Quick actions

cmd+k|ctrl+k

Navigation

Languages

While loop 1

Snippet info

Language

Python

Visibility

public

Author

chausage

Created

2024-12-02T09:01:22.075231Z

Updated

2024-12-02T09:01:22.075231Z

x=10
while x>= 0:
    x=x-1 #controller, otherwise 無限loop
    if x%2:# %:Remainder, 餘數
        x=-1
        continue #go back to top
    if x==4:
        break #end/exit loop
    print(x)
    
else:
    print("This line will run when while loop is false.")
    
INFO