break:跳出循环 ,continue:停止当前循环,进入下一次循环,但为跳出循环。
passwdList=["123","456"] valid = False count = 3 while count > 0: input = raw_input("enter password: ") for eachPasswd in passwdList: if input == eachPasswd: valid = True break #跳出for循环,继续while循环 if not valid: # (or valid == 0) print "invalid input" count -= 1 continue #进入下一次while循环 else: break #跳出while循环
时间: 2024-11-04 15:04:31