标签:while for if break continue python语句
1.for语句:
脚本实例:
#!/usr/bin/python
for i in range(1,15):
print i
else:
print ‘The loop is done !‘
2.while/if语句:
脚本实例:
#!/usr/bin/env python
#FileName:while1.py
running = True
a = 20
b = int(raw_input(‘Enter A number b: ‘))
while running:
if a == b:
print ‘ good,Your number is Ture ! !‘
running = False #状态为False则终止循环
else:
print ‘Bad,Pleas Try Again!‘
print ‘Done‘
3.break语句:
脚本实例:
#!/usr/bin/env python
#FileName:while1.py
running = True
a = 20
b = int(raw_input(‘Enter A number b: ‘))
while running:
if a == b:
print ‘ good,Your number is Ture ! !‘
break #终止循环
else:
print ‘Bad,Pleas Try Again!‘
print ‘Done‘
4.continue语句:
脚本实例:
#!/usr/bin/python
#FileName:continue.py
while True:
A = int(raw_input(‘Enter A Number:‘))
if A == 23:
print "The number is %s !" % A
break
if A != 23:
print "please continue enter number."
continue #符合该条件则继续循环
print "Done"
标签:while for if break continue python语句
原文地址:http://liupengfang1015.blog.51cto.com/6627801/1742770