一、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
>>>




相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-01-10
猜你喜欢
  • 2022-01-03
  • 2022-02-07
  • 2021-11-10
  • 2021-10-17
  • 2021-05-26
  • 2022-12-23
  • 2021-10-24
相关资源
相似解决方案