shellScript之break关键字
来源:互联网 发布:福大图书馆数据库 编辑:程序博客网 时间:2024/05/17 04:55
#!/bin/bashsum=0for (( i = 1; i <= 100; i++))do let "sum+=i" if [ "$sum" -gt 1000 ];thenecho "1+2+3...$i=$sum"break fidone
结果:
~/Note/test # ./17break.sh 1+2+3...45=1035
例子2:
#!/bin/bashfor (( i = 1;i <= 9;i++))do for (( j = 1;j <= i;j++)) dolet "temp=i*j"if [ "$temp" -eq 7 ];then breakfiecho -n "$i*$j=$temp " done echo ""done
结果:
~/Note/test # ./18break.sh 1*1=1 2*1=2 2*2=4 3*1=3 3*2=6 3*3=9 4*1=4 4*2=8 4*3=12 4*4=16 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
例子3:
#!/bin/bashfor (( i = 1;i <= 9; i++))do if [ "$i" -eq 7 ];thenbreak fi for (( j = 1;j <= i;j++)) dolet "temp = i*j"echo -n "$i*$j=$temp " doneecho ""done
结果:
~/Note/test # ./19break.sh 1*1=1 2*1=2 2*2=4 3*1=3 3*2=6 3*3=9 4*1=4 4*2=8 4*3=12 4*4=16 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
阅读全文
0 0
- shellScript之break关键字
- shellScript之位置参数
- shellScript之if_else语句
- shellScript之if_elif_else语句
- shellScript之case语句
- shellScript之for语句
- shellScript之while语句
- shellScript之while语句
- shellScript之util语句
- shellScript之continue语句
- shellScript之select语句
- shellScript之hello函数
- shellScript之嵌套if_else语句
- shellScript之数组操作1
- shellScript之数组操作2
- shellScript之数组操作3
- shellScript之数组操作4
- shellScript之数组操作5
- 【大数据部落】SPSS中国延迟退休调查报告——延迟退休,你准备好了吗?
- c语言编程--判断一个32位寄存器中的第8位是否是1
- Ubuntu16 复制一个文件到指定目录下
- WEB项目开发的一般流程
- Android学习之Service(下)
- shellScript之break关键字
- 机器学习笔记十八 FP-growth
- mysql中Invalid default value for 'stime'问题
- Laravel 5.4 官方文档摘记:路由
- poj 字符串相关之3038
- 决策树与随机森林算法(理论)-----------------------机器学习系列(二))
- mysql 得到的数据插入另一个新表中
- 机器学习笔记十九 使用PCA简化数据(未完)
- 树链剖分(bzoj 1036: [ZJOI2008]树的统计Count)