10,break语句:
break语句是用来终止循环语句的,即,哪怕循环条件没有到false或序列还没有被完全递归,也停止执行循环语句;
while True:
s = raw_input('enter something:')
if s == 'quit'
break
print 'length of the string is',len(s)
print 'done'
保存退出;
$ python break.py
enter something:while
length of the string is 5
enter something:hello
length of the string is 5
enter something:quit
done
11,continue语句:、
continue语句被用来告诉python跳过当前循环块中剩下的语句,然后继续下一轮循环:
while True:
s = raw_input('enter something')
if s == 'quit':
break
if len(s) < 3:
continue
print 'input is of sufficient length'
保存退出;
$ python continue.py
entry something:123
input is of sufficient length
entry something:wer
input is of sufficient length
entry something:quite
input is of sufficient length
entry something:quit
if、while和for以及与它们相关的break和continue语句。它们是Python中最常用的部分,熟悉这些控制流是应当掌握的基本技能。