python
s=0
i=1
while i<11:
s+=i
if s>20:
print('累加:',i)
break
i+=1
print('*'*40)
i=0
while i<3:
user_name=input('用户名:')
pin=input('pin:')
if user_name=='xy'and pin=='666':
print('对了')
break
else:
if i<2:
print('deadline',2-i,'coutdown')
i+=1
else:
print('错误:')
以上是while与break连用,while与break else连用
for与break
python
for i in 'hello':
if i=='e':
break
print(i)
print('-'*20)
for i in range(3):
user_name=input('用户名:')
pin=input('请输入密码:')
if user_name=='xy'and pin=='666':
print('对了')
break
else:
if i<2:
print('haiyou',2-i,'dd')
else:
print('均错误')
程序跳转语句(continue)分别在while与在for循环中的使用
python
s=0
i=1
while i<=100:
if i%2==1:
i+=1
continue
s+=i
i+=1
print('偶数和:',s)
print('*'*20)
s=0
for i in range(1,101):
if i%2==1:
continue
s+=i
print('1-100:',s)