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