返回列表 發帖

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,101):
  2.     if(i==94):
  3.         break
  4.     print(i)
複製代碼

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

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.     if(i==6):
  3.         break
  4.     print(i, end=",")
  5.    
複製代碼

TOP

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

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.     if(i==6):
  3.         break
  4.     print(i,end=',')
複製代碼

TOP

  1. for c in range(1,13):
  2.     if(c==7):
  3.         break
  4.     print(c, end="...")
  5. print("__")
  6. for y in range(1,17):
  7.     if(y==9):
  8.         continue
  9.     print(y, end="")
複製代碼
._.

TOP

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

TOP

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

TOP

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

TOP

返回列表