Python 關鍵字
如果變量 i 為 5,則跳過迭代,但繼續進行下一個迭代:
for i in range(9): if i == 5: continue print(i)
運行實例
continue 關鍵字用于在 for 循環(或 while 循環)中結束當前迭代,然后繼續下一個迭代。
在 while 循環中使用 continue 關鍵字:
i = 0 while i < 9: i += 1 if i == 5: continue print(i)
使用 break 關鍵字 徹底結束循環。
請在我們的 Python For 循環教程 中學習更多有關循環的知識。
請在我們的 Python While 循環教程 中學習更多有關循環的知識。