zoukankan      html  css  js  c++  java
  • python的while例子

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    
    import time
    import sys
    import os
    
    
    # 主程序
    if __name__ == "__main__":
        NUM = 0
        while True:
            NUM += 1
            print ( "{1}---执行第{0}次轮询。".format(NUM,time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
            try:
                Valuses = 10
                #数据就绪时退出
                if NUM < Valuses:
                    print '当前数据值:' + str(NUM) +  '小于给定数据值10,继续执行...'
                    time.sleep(3)
                else:
                    print '当前数据值:' + str(NUM) +  '大于等于给定数据值10,执行完成!'
                    break
            except Exception as e:
                print e.message
                sys.exit(1)

    运行结果:

    2020-11-05 18:34:37---执行第1次轮询。
    当前数据值:1小于给定数据值10,继续执行...
    2020-11-05 18:34:40---执行第2次轮询。
    当前数据值:2小于给定数据值10,继续执行...
    2020-11-05 18:34:43---执行第3次轮询。
    当前数据值:3小于给定数据值10,继续执行...
    2020-11-05 18:34:46---执行第4次轮询。
    当前数据值:4小于给定数据值10,继续执行...
    2020-11-05 18:34:49---执行第5次轮询。
    当前数据值:5小于给定数据值10,继续执行...
    2020-11-05 18:34:52---执行第6次轮询。
    当前数据值:6小于给定数据值10,继续执行...
    2020-11-05 18:34:55---执行第7次轮询。
    当前数据值:7小于给定数据值10,继续执行...
    2020-11-05 18:34:58---执行第8次轮询。
    当前数据值:8小于给定数据值10,继续执行...
    2020-11-05 18:35:01---执行第9次轮询。
    当前数据值:9小于给定数据值10,继续执行...
    2020-11-05 18:35:04---执行第10次轮询。
    当前数据值:10大于等于给定数据值10,执行完成!
  • 相关阅读:
    runtime iOS 运行时机制
    iOS 文件操作
    responseCode 状态吗查询
    iOS常用宏定义
    Block里用self造成循环引用
    iOS Block全面分析
    OC与Swift混编
    iOS打包app发给测试人员测试
    Swift UITextField
    sqilite学习
  • 原文地址:https://www.cnblogs.com/hello-wei/p/13933316.html
Copyright © 2011-2022 走看看