break 和 continue

一、break

break的功能是跳出循环。如果使用了多个嵌套的循环,还可以指定要跳出的循环数。

[root@localhost shell]# cat test.sh

#!/bin/bash

#This is a test script.
#2013/12/16

while true
do
        while true
        do
                echo "inner while"
                break 2
        done
        echo "outer while"
done

echo "I am out"

[root@localhost shell]# ./test.sh
inner while
I am out

二、continue

continue的功能不是跳出循环,而只是提前结束本次循环过程,重新开始下一次循环过程。同样,continue也可以接受可选的数值参数,用来指出要继续的循环层次数。

原文地址:https://www.cnblogs.com/nufangrensheng/p/3483973.html