zoukankan      html  css  js  c++  java
  • 控制流之continue

    continue语句
    continue语句被用来告诉Python跳过当前循环块中的剩余语句,然后 继续 进行下一轮循环。
    使用continue语句
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    例6.5 使用continue语句

    #!/usr/bin/python
    # Filename: continue.py
    while True: 
        s = raw_input('Enter something : ') 
        if s == 'quit': 
            break 
        if len(s) < 3:
         continue
        print 'Input is of suficient lenhth'

    它如何工作
    在这个程序中,我们从用户处取得输入,但是我们仅仅当它们有至少3个字符长的时候才处理它们。所以,我们使用内建的len函数来取得长度。如果长度小于3,我们将使用continue语句忽略块中的剩余的语句。否则,这个循环中的剩余语句将被执行,我们可以在这里做我们希望的任何处理。
    注意,continue语句对于for循环也有效。

  • 相关阅读:
    牛顿迭代法
    C语言补遗
    Manjaro添加开机启动脚本
    tensorboard查看pytorch模型
    Kindle最佳排版记录
    01背包问题详解
    差分法介绍
    BFS详解
    UVA11732 "strcmp()" Anyone?
    LA3942 Remember the Word
  • 原文地址:https://www.cnblogs.com/losbyday/p/5866392.html
Copyright © 2011-2022 走看看