UNPKG

1.06 kBMarkdownView Raw
1continue
2===
3
4结束本次循环,继续执行下一个for,while或until循环。
5
6## 概要
7
8```shell
9continue [n]
10```
11
12## 主要用途
13
14- 结束本次循环,继续执行下一个for,while或until循环;可指定从第几层循环继续执行。
15
16
17## 参数
18
19n(可选):大于等于1的整数,用于指定从第几层循环继续执行。
20
21## 返回值
22
23返回状态为成功除非n小于1。
24
25## 例子
26
27```shell
28# continue的可选参数n缺省值为1。
29for((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
38done
39# 输出结果
403 3
413 1
422 3
432 1
441 3
451 1
46```
47
48```shell
49# 当n为2时:
50# 跳到外层for循环继续执行。
51for((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
58done
59# 输出结果
603 3
612 3
621 3
63```
64
65### 注意
66
671. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
68
69
70