Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1438453
  • 博文数量: 244
  • 博客积分: 3353
  • 博客等级: 中校
  • 技术积分: 3270
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-09 17:56
文章分类

全部博文(244)

文章存档

2023年(7)

2022年(7)

2021年(4)

2020年(1)

2019年(2)

2017年(2)

2016年(3)

2015年(11)

2014年(20)

2013年(10)

2012年(176)

分类: Python/Ruby

2012-06-25 22:38:16


当使用continue时,只是终止余下的操作,而不会跳出整个循环
  1. #!/bin/bash
  2. limit=19
  3. echo "printing Number 1 throught 20"
  4. a=0
  5. while [ $a -le "$limit" ]
  6. do
  7. let a++
  8. #let a+=1
  9. #a=$(($a+1))
  10. if [ "$a" -eq 3 ] || [ "$a" -eq 11 ]
  11. then
  12. continue
  13. fi
  14. echo -n "$a "
  15. done
输出结果
  1. $ ./continue.sh
  2. 1 2 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20

使用break跳出循环,符合条件跳出整个循环
  1. #!/bin/bash
  2. limit=19
  3. echo "printing Number 1 throught 20"
  4. a=0
  5. while [ $a -le "$limit" ]
  6. do
  7. let a++
  8. #let a+=1
  9. #a=$(($a+1))
  10. if [ "$a" -eq 3 ] || [ "$a" -eq 11 ]
  11. then
  12. #continue
  13. break
  14. fi
  15. echo -n "$a "
  16. done

输出结果

  1. $ ./continue.sh
  2. 1 2



 
阅读(1706) | 评论(0) | 转发(0) |
0

上一篇:string学习(07)

下一篇:关键字驱动测试

给主人留下些什么吧!~~