在Python中继续似乎存在一些严重的问题:例如:
for i in range(1,10):
if i % 2 == 0:
continue
print i
Run Code Online (Sandbox Code Playgroud)
按预期工作,但是
i = 0
while(i < 10):
if i %2 == 0:
continue
i += 1
print i
Run Code Online (Sandbox Code Playgroud)
while循环永远不会终止!
i在第二个片段中,您永远不会增加.删除继续.
i = 0
while(i < 10):
if i %2 == 0: # i == 0; continue without increment the value of i <-- stuck here!
continue
i += 1
print i
Run Code Online (Sandbox Code Playgroud)