1.2.3.3 while/break/continue
典型的C式While循环(Mandelbrot问题):
In [13]:
z = 1 + 1j
while abs(z) < 100:
z = z**2 + 1
z
Out[13]:
(-134+352j)
更高级的功能
bread 跳出for/while循环:
In [103]:
z = 1 + 1j
while abs(z) < 100:
if z.imag == 0:
break
z = z**2 + 1
print z
(1+2j)
(-2+4j)
(-11-16j)
(-134+352j)
continue 继续下一个循环迭代:
In [101]:
a = [1, 0, 2, 4]
for element in a:
if element == 0:
continue
print 1. / element
1.0
0.5
0.25