python PYループ突破,继续

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python PYループ突破,继续相关的知识,希望对你有一定的参考价值。

# for - continue
words = ["Alpha", "Bravo", "Charlie", "Delta", "END", "Foxtrot"]

for word in words:
	if word == "END":
		continue
	print(word)
"""
Alpha
Bravo
Charlie
Delta
Foxtrot
"""
# for - break
words = ["Alpha", "Bravo", "Charlie", "Delta", "END", "Foxtrot"]
words2 = ["Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot"]

for word in words:
	if word == "END":
		print("*BREAK!")
		break
	print(word)
else:
	print("*END*")
"""
Alpha
Bravo
Charlie
Delta
*BREAK!
"""

for word in words2:
	if word == "END":
		print("*BREAK!")
		break
	print(word)
else:
	print("*END*")
"""
Alpha
Bravo
Charlie
Delta
Echo
Foxtrot
*END*
"""

# while - break
pw = "1234"

while True:
	enter_pw = input("PW: ")
	if enter_pw == pw:
		print("--OK--")
		break
	else:
		print("==ERROR==")

以上是关于python PYループ突破,继续的主要内容,如果未能解决你的问题,请参考以下文章

php データ膨大の时の配列ループ

text jQuery的【配列·连想配列】ループ处理

swift 对于ループの中でや继续突破を使用しているのを,过滤に书き换える

python PYループ而

EXIT,CONTINUE,CHECK(ロープの終了)

text PYループ内包表记