continue && break

本文通过两个Python示例展示了如何使用continue和break控制循环流程。第一个示例中,当循环变量等于3时,利用continue跳过该次循环中剩余的代码并继续下一次迭代;第二个示例中,当循环变量等于3时,则使用break提前结束整个循环。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

print"\n\n************contiue*********************"
for i in range (1,6):
   print
   print 'i =',i,
   print 'hello,how',

   if i ==3:
       continue

   print 'are you today?'

print"\n\n************break**********************"
   
for i in range (1,6):
   print
   print 'i =',i,
   print 'hello,how',

   if i ==3:
       break

   print 'are you today?'


运行结果:

************contiue*********************

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**********************

i = 1 hello,how are you today?

i = 2 hello,how are you today?

i = 3 hello,how


 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值