python continue 语句跳出本次循环,而break跳出整个循环。
continue 语句用来告诉python跳过当前循环的剩余语句,然后继续进行下一轮循环。
continue语句用在while和for循环中。
python 语言 continue 语句语法格式如下:
continue
流程图:
实例:
#!/usr/bin/python
for letter in ‘python’: # first example
if letter == ‘h’:
continue
print ‘current letter :’, letter
var = 10 # second example
while var > 0:
var = var -1
if var == 5:
continue
print ‘current variable value :’, var
print “good bye!”
以上实例执行结果:
current letter : p
current letter : y
current letter : t
current letter : o
current letter : n
current variable value : 9
current variable value : 8
current variable value : 7
current variable value : 6
current variable value : 4
current variable value : 3
current variable value : 2
current variable value : 1
current variable value : 0
good bye!