返回列表 發帖

break 與 continue

break 指令強制跳離迴圈
  1. for i in range(1,11):
  2.     if(i==6):
  3.         break
  4.     print(i, end=",")
複製代碼


continue 指令強制進入下一輪迴圈
  1. for i in range(1,11):
  2.     if(i==6):
  3.         continue
  4.     print(i, end=",")
複製代碼

  1. for i in range(1,10):
  2.     if i==6:
  3.         break
  4.     print(i)
  5.    
  6. for i in range(1,20):
  7.     if i==10:
  8.         continue
  9.     print(i)
複製代碼

TOP

  1. for i in range(1,11):
  2.     if(i==6):
  3.         break
  4.     print(i,end=" ")        
複製代碼

TOP

for i in range(1,100):
    if i==10:
          break
print(i)

TOP

for i in range(1,11):
    if(i==6):
        continue
    print(i, end=",")

TOP

  1. for i in range(1,101):
  2.     if i ==51:
  3.         break
  4.     print(i,end=" ")

  5. for j in range(1,101):
  6.     if i ==51:
  7.         continue
  8.     print(i,end=" ")
複製代碼

TOP

for i in range(1,100):
    if i==10:
        break
    print(i)
for i in range(1,100):
    if i==10:
        continue
    print(i)

TOP

  1. for i in range(1,11):
  2.     if(i==6):
  3.         break
  4.     print(i, end=",")
  5.    
  6.     print(" ")
  7.    
  8. for i in range(1,11):
  9.     if(i==6):
  10.         continue
  11.     print(i, end=",")
  12.     print(" ")
複製代碼

TOP

  1. for i in range(1,100):
  2.     if(i==10):
  3.         break
  4.     print(i)
複製代碼

TOP

  1. for i in range(1,11):
  2.     if(i==6):
  3.         break
  4.     print(i, end=" ")
複製代碼

TOP

  1. for i in range(1,11):
  2.     print(i)
  3.     if i==5:
  4.         break
  5. for i in range(1,11):
  6.     if i==5:
  7.         continue
  8.     print(i)
複製代碼

TOP

  1. for i in range(1,10):
  2.     if i==6:
  3.         break
  4.     print(i)
  5.    
  6. for i in range(1,20):
  7.     if i==10:
  8.         continue
  9.     print(i)
複製代碼

TOP

  1. for i in range(1,11):
  2.     if(i==6):
  3.         break
  4.     print(i,end=",")
  5.    
  6.     for i in range(1,11):
  7.         if(i==6):
  8.             continue
  9.         print(i,end=",")
複製代碼

TOP

  1. for i in range(1,21):
  2.     if(i==10):
  3.         break
  4.     print(i,end="," )
複製代碼
  1. for i in range(1,21):
  2.     if(i==10):
  3.         continue
  4.     print(i,end="," )
複製代碼

TOP

  1. a=0
  2. for i in range(1,10):
  3.     if(i==6):
  4.         break
  5.     print(i)
複製代碼

TOP

8

TOP

  1. for i in range(1,11):
  2.     if(i==6):
  3.         break
  4.     print(i, end=",")
複製代碼

TOP

for i in range(1,10):
    if i==4:
        continue
    if i==9:
        break
    print(i)

TOP

for i in range(2,101):
    if i%2==1:
        continue
    print(i)

TOP

返回列表