linux类似break的用法,break(循环转义或前进)_语法_示例_Unix&Linux命令_uc电脑园官网...

In the following shell script, the break command exits from a while loop when the variable a has a value of 5 or greater:

#!/bin/sh

a=0

while [ $a -lt 10 ]

do

echo $a

if [ $a -eq 5 ]

then

break

fi

a=$(( $a + 1 ))

done

...and produces the following output:

0

1

2

3

4

5

This next example uses the form break n to break from a nested loop.

#!/bin/sh

for var1 in 1 2 3

do

for var2 in 0 1 2 3

do

if [ $var1 -eq 2 -a $var2 -eq 1 ]

then

break 2

else

echo "$var1 $var2"

fi

done

done

In the above script, the outer loop sets var1 to 1, then the inner loop sets var2 to the values 0, 1, 2, and 3, respectively. Then the outermost loop sets var1 to 2 and the inner loop sets var2 to the values of 0 and 1 — at which point the conditions are met to execute break 2, which terminates both loops. It will produce the following output:

1 0

1 1

1 2

1 3

2 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值