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循环也有效。

相关文章:

  • 2021-12-31
  • 2021-06-19
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-12-19
猜你喜欢
  • 2022-01-05
  • 2021-09-30
  • 2022-02-08
  • 2022-01-05
  • 2022-01-11
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案