Loop StatementsΒΆ
- For loops:
>>> l = [1, 2, 3]; tot = 0
>>> for elem in l:
... tot += elem
...
... print tot, sum(l)
6 6
- While loops:
>>> i = 0
>>> while i < 3:
... print i
... i += 1
...
0
1
2
>>> l = [1, 2, 3]; tot = 0
>>> for elem in l:
... tot += elem
...
... print tot, sum(l)
6 6
>>> i = 0
>>> while i < 3:
... print i
... i += 1
...
0
1
2