zoukankan      html  css  js  c++  java
  • 初识while循环

    while 条件:

      代码块

    print()

    定时器:import time ,time.sleep(1),等待1秒

    n=True

    while n:

      print('1')

      time.sleep(1)

      n=False

    print('end')

    =============================================

    import time 

    kaishi = 1

    flag=True

    while flag:

      print(kaishi)

      if kaishi == 10

        flag=false

      kaishi=kaishi + 1

      time.sleep(1)

    print('end')

    ============================================

    break ---用于跳出循环

    kaishi =1

    while True:

      print(kaishi)

      if kaishi ==10

        break

      kaishi = kaishi +1

    ============================================

    continue---用于跳出本次循环,继续下次循环

    while True:

      print('123')

      continue

      print('456')

    只能输入123,一直输出,而不能输出456

    ==========================================

    输出1到10

    start = 1

    while True:

      print(start)

      if start == 10:

        break

      #start = start + 1

      start +=1

    ==========================================

    输出1 2 3 4 5 6 8 9 10

    start = 1

    while True:

      if start ==7:

        start +=1

        continue

      print(start)

      if start == 10:

        break

      #start = start + 1

      start +=1

    ==========================================

    1 到 100 所有数的和

    i=1

    sum=0

    while true:

      print(i)

      sum = sum + i

      if i ==100:

        break

      i=i+1

    print(sum)

    ==========================================

    1 到 100 所有奇数的和

    i=1

    sum=0

    while true:

      print(i)

      if i % 2 ==1:

        sum = sum + i

      if i ==100:

        break

      i=i+1

    print(sum)

    ==========================================

    1 到 100 所有偶数的和

    i=1

    sum=0

    while true:

      print(i)

      if i % 2 ==0:

        sum = sum + i

      if i ==100:

        break

      i=i+1

    print(sum)

      

  • 相关阅读:
    初创业公司怎么开拓市场?(转)
    谈谈创业初期公司拓展业务的心得(转)
    互联网产品消息推送设计策略(转)
    如何成为一名合格的CTO?(转)
    jackson JsonPropertyOrder和@JsonIgnoreProperties注解
    tomcat报java.lang.VerifyError错误
    FAQ unzip无法解压文件
    Oracle监听启动失败问题
    F5 BIG-IP负载均衡器配置实例与Web管理界面体验
    如何查询 Oracle 11g日志
  • 原文地址:https://www.cnblogs.com/huangguabushihaogua/p/9214263.html
Copyright © 2011-2022 走看看