話不多說,實(shí)踐見真知鸳劳。(python環(huán)境是python2.7)
#!/usr/bin/env python
# -*- coding=utf-8 -*-
def func():
# break 結(jié)束循環(huán)也搓,條件成立循環(huán)終止,后面的就不再執(zhí)行
# 輸出 0 1 2
for x in range(6):
if x == 3:
break
print x
# continue 結(jié)束當(dāng)次循環(huán)幔摸, 條件成立颤练,本次不執(zhí)行既忆,當(dāng) x==3時(shí)結(jié)束嗦玖,繼續(xù)下一次循環(huán)
# 輸出 0 1 2 4 5
# print [x for x in range(6) if x != 3]
for x in range(6):
if x == 3:
continue
print x
if __name__ == '__main__':
func()