[zurück]

2.5. Schleifen

[vor]

xrange und range

N=5
for i in xrange(0,N):
    print(i)
0
1
2
3
4

N=5
for i in range(0,N):
    print(i)
0
1
2
3
4

N=8
for i in range(0,N, 2):
    print(i)
0
2
4
6

while

x = 0
while x < 5:
    print(x)
    x = x + 1
0
1
2
3
4

x = 2
while x**2 <= 100:
    print(x**2)
    x = x + 1
4
9
16
25
36
49
64
81
100


[zurück] [Inhaltsverzeichnis] [vor]