Skip to content

Commit 1806f69

Browse files
authored
Create continue.md
创建文件
1 parent 8ee0864 commit 1806f69

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

command/continue.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
continue
2+
===
3+
4+
结束本次循环,继续执行下一个for,while或until循环。
5+
6+
## 概要
7+
8+
```shell
9+
continue [n]
10+
```
11+
12+
## 主要用途
13+
14+
- 结束本次循环,继续执行下一个for,while或until循环;可指定从第几层循环继续执行。
15+
16+
17+
## 参数
18+
19+
n(可选):大于等于1的整数,用于指定从第几层循环继续执行。
20+
21+
## 返回值
22+
23+
返回状态为成功除非n小于1。
24+
25+
## 例子
26+
27+
```shell
28+
# continue的可选参数n缺省值为1。
29+
for((i=3;i>0;i--)); do
30+
# 跳到内层for循环继续执行。
31+
for((j=3;j>0;j--)); do
32+
if((j==2)); then
33+
# 换成continue 1时结果一样
34+
continue
35+
fi
36+
printf "%s %s\n" ${i} ${j}
37+
done
38+
done
39+
# 输出结果
40+
3 3
41+
3 1
42+
2 3
43+
2 1
44+
1 3
45+
1 1
46+
```
47+
48+
```shell
49+
# 当n为2时:
50+
# 跳到外层for循环继续执行。
51+
for((i=3;i>0;i--)); do
52+
for((j=3;j>0;j--)); do
53+
if((j==2)); then
54+
continue 2
55+
fi
56+
printf "%s %s\n" ${i} ${j}
57+
done
58+
done
59+
# 输出结果
60+
3 3
61+
2 3
62+
1 3
63+
```
64+
65+
### 注意
66+
67+
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
68+
69+
70+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

0 commit comments

Comments
 (0)