Create break.md

创建文件
This commit is contained in:
ZhuangZhu-74 2019-07-23 15:50:28 +08:00 committed by GitHub
parent 1806f69d7f
commit 99ed928ba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 0 deletions

65
command/break.md Normal file
View File

@ -0,0 +1,65 @@
break
===
结束forwhile或until循环。
## 概要
```shell
break [n]
```
## 主要用途
- 结束forwhile或until循环可指定退出几层循环。
## 参数
n可选大于等于1的整数用于指定退出几层循环。
## 返回值
返回成功除非n小于1。
## 例子
```shell
# break的可选参数n缺省值为1。
# 从外层for循环继续执行。
for((i=3;i>0;i--)); do
for((j=3;j>0;j--)); do
if((j==2)); then
# 换成break 1时结果一样
break
fi
printf "%s %s\n" ${i} ${j}
done
done
# 输出结果
3 3
2 3
1 3
```
```shell
# 当n为2时
# 退出两层循环,结束。
for((i=3;i>0;i--)); do
for((j=3;j>0;j--)); do
if((j==2)); then
break 2
fi
printf "%s %s\n" ${i} ${j}
done
done
# 输出结果
3 3
```
### 注意
1. 该命令是bash内建命令相关的帮助信息请查看`help`命令。
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->