退出循环语句

退出循环语句

# 案例1

while 1:
    name = input("用户名:")
    pwd = input("密码:")
    if name = "rain" and pwd == "123"
        print("登录成功!")
        break
    else:
        print("登录失败")
        
print("程序继续!")

# 计算1+2+3+4+5+65+67+...100的结果
count = 0
num = 0
while count < 100:  # 循环语句
    count += 1  # 步进语句: count = count +1
    if count == 66:
        # break   # 退出整个循环
        continue  # 退出当次循环

    num = num + count

print(num)

 

posted @ 2023-05-10 12:38  卡卡罗安  阅读(112)  评论(0)    收藏  举报