5.25 continue break for while
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.25 continue break for while相关的知识,希望对你有一定的参考价值。
#_author:"ljk"
#date: 2017/5/25
# 1、break,中断当前循环
# for i in range(10): #打印5-9
# if i < 5:
# continue #跳出当前循环
# print(i)
# for j in range(10):
# print("layer2",j)
# if j == 6:
# break
#2 break 一次只能中断一层循环
# for i in range(10): #打印5-9
# if i < 5:
# continue #跳出当前循环
# print(i)
# for j in range(10):
# print("layer2",j)
# if j == 6:
# break
# break #break一次最多只能中断一层的循环,再中断再break
#
#3
# exit_flag = False
# for i in range(10): #打印5-9
# if i < 5:
# continue #跳出当前循环
# print(i)
# for j in range(10):
# print("layer2",j)
# if j == 6:
# exit_flag = True#如果没有这一句,则运行结果同上,下一层循环不能执行
# break
# if exit_flag:#因为 exit_flag = True,所以才可以下一层的flag
# break #break一次最多只能中断一层的循环,再中断再break
# user1 = "ljk"
# password1 = "123"
# counter = 0
# while counter <3:
# user = input("USER:")
# password = input("PASSWORD:")
# if user ==user1 and password == password1:
# print("welcom")
# break
# else:
# print("please try again")
# counter += 1
# if counter == 3:
# keep_going = input("还想玩么?[y/n]")
# if keep_going == "y":
# counter = 0
# else: #while 循环正常结束后,会执行该else,如果break之后就不会执行
# print("Stop!不要脸的!")
以上是关于5.25 continue break for while的主要内容,如果未能解决你的问题,请参考以下文章
Javascript for循环语句以及break和continue的使用
请说明break和continue的区别?用JAVA举例出来详细点··要例子