zoukankan      html  css  js  c++  java
  • Python中的break和continue的使用方法


    一、continue的使用方法(结束当前的循序,进行下一个数的循环)

    # *****************************************************************************
    # This is a program to illustrate the useage of continue in Python.
    # If you want to stop executing the current iteration of the loop and skip ahead to the next 
    # continue statement is what you need. 
    # ****************************************************************************
    for i in range (1,6):
        print
        print 'i=',i,
        print 'Hello,how',
        if i==3:
            continue
        print 'are you today?'
    

    执行结果例如以下:

    >>> ================================ RESTART ======================
    >>>

    i= 1 Hello,how are you today?

    i= 2 Hello,how are you today?

    i= 3 Hello,how
    i= 4 Hello,how are you today?



    i= 5 Hello,how are you today?
    >>> 


    二、break的使用方法(结束总的循环)

    # *****************************************************************************
    # This is a program to illustrate the useage of break in Python.
    # What if we want to jump out of the loop completely—never finish counting, or give up
    # waiting for the end condition? break statement does that.
    # ****************************************************************************
    for i in range (1,6):
        print
        print 'i=',i,
        print 'Hello,what is ',
        if i==3:
            break
        print 'the weather today?'
    
    执行结果例如以下:

    >>> ================================ RESTART ========================
    >>>

    i= 1 Hello,what is  the weather today?

    i= 2 Hello,what is  the weather today?

    i= 3 Hello,what is
    >>>




  • 相关阅读:
    js获取Session问题 dodo
    复制一个datatable的指定行到另外一个datatable dodo
    sqlserver数据库备份与还原语句 dodo
    net软件测试实战技术大全 dodo
    AJAX 浏览器支持 dodo
    使用 vs2005进行负载测试 dodo
    sql使用in批量删除 dodo
    各种浏览器兼容存在的方法:Xenocode Browser Sandbox dodo
    C#调用Windows API函数 dodo
    ewebeditor在ie8下报错 dodo
  • 原文地址:https://www.cnblogs.com/llguanli/p/6729367.html
Copyright © 2011-2022 走看看