zoukankan      html  css  js  c++  java
  • 7.while循环,exit,contiune,break,死循环

    count=0
    while count<100:
    print("loop",count)
    if count==5:
    break
    count+=1
    print("-----and----")
    # 到数字5退出


    count = 0
    while count < 100:
    count += 1
    if count == 5:
    continue # 到5以后,回到前面,count不会加一
    print("loop", count)
    # 输出1-100.不含5


    count=0
    while count<100:
    count+=1
    if count>5 and count<95:
    continue
    print("loop",count)
    print("------and-------")
    #跳过6-94




    while循环
    count=0
    while count<100:
    print("我要一个小宝宝")
    count+=1

    求偶数
    count=0
    while count<100:
    if count%2==0:
    print("我要一个小宝宝", count)
    count+=1

    求奇数
    count=0
    while count<100:
    if count%2==1:
    print("我要一个小宝宝", count)
    count+=1



    import random
    n=random.randint(1,10)
    print(n)
    count=0
    while count<5:
    user_guess=int(input("请输入:"))
    if user_guess>n:
    print("太大了")
    elif user_guess<n:
    print("太小了")
    else:
    print("niubility")
    exit() # 终止整个程序,print(count)不打印
    count+=1
    print(count)

    import random
    n=random.randint(1,10)
    print(n)
    count=0
    while count<5:
    user_guess=int(input("请输入:"))
    if user_guess>n:
    print("太大了")
    elif user_guess<n:
    print("太小了")
    else:
    print("niubility")
    break # 终止整个循环,print(count)打印
    count+=1
    print(count)

    count=0
    while count<100:
    count+=1
    if count>10 and count<20:
    continue # 终止当次循环,继续下次循环
    print(count)

    else:# 当循环正常结束,条件不成立了,执行
    print("Dsds")

    break continue 等需要在循环语句中才能使用。for循环也可以


    死循环
    deadloop
    while true:
      print("你是傻逼吗?")
  • 相关阅读:
    UDP案例_在线咨询
    MFC对话框水平和垂直滚动条功能
    对话框中滚动条
    ON_COMMAND_RANGE 多个按钮响应一个函数
    char**赋值
    MFC如何使dialog对话框置顶
    如何让CListBox控件滚动条自动向下滚动?
    不带,以及带参数,带返回值的Lambda表达式
    JAVA学习_多线程技术
    最烦有些技术帖上来就放代码
  • 原文地址:https://www.cnblogs.com/xh716/p/11548486.html
Copyright © 2011-2022 走看看