.. getthecode:: loop.py :language: python3 :hidden: ======= Loops ======= This page contains a memo on loop statements. For Loop -------- .. code-block:: py3 for i in range(5): print(i) else: print('end') .. code-block:: none 0 1 2 3 4 end .. code-block:: py3 for i in range(1000): if 5 < i: break print(i) else: print('end') .. code-block:: none 0 1 2 3 4 5 .. code-block:: py3 for i in range(100): if not (10 < i < 16): continue print(i) else: print('end') .. code-block:: none 11 12 13 14 15 end While Loop ---------- .. code-block:: py3 i = 0 while i < 5: print(i) i += 1 else: print('end') .. code-block:: none 0 1 2 3 4 end .. code-block:: py3 i = 0 while i < 1000: if 5 < i: break print(i) i += 1 else: print('end') .. code-block:: none 0 1 2 3 4 5