返回列表 發帖

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,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=",")
複製代碼
  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

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

TOP

返回列表