本文介绍了如果猛砸 - >那么如果 - >否则跳到第一ELIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
code:
if [cond1]
then if [cond2]
then ...
else skip to elif
fi
elif[cond3]
then ...
fi
如果第二个条件不匹配跳到ELIF。
If second condition doesn't match skip to elif.
推荐答案
请注意,在低于code, ELIF QUUX ...
是任何一个占位符 ELIF
你得了之后 ELIF cond3
。
Note that in the below code, elif quux...
is a placeholder for whatever elif
s you have after elif cond3
.
的(也就是说,你希望在你跳过执行其code,即使 cond3
是假的。)的
(That is, you want to execute its code when you skip, even if cond3
is false.)
正如@ code4me建议,你可以使用一个功能:
As suggested by @code4me, you could use a function:
foo() {
# do work
}
if cond1; then
if cond2; then
...
else
foo
fi
elif cond3; then
foo
elif quux...
这也是@ fedorqui的建议如下:
This is also where @fedorqui's suggestion works:
if cond1 && cond2; then
...
elif cond3; then
# do work
elif quux...
如果您的不的需要测试 cond3
上跳过
逻辑变得更难理解。
If you do need to test cond3
on skipping
The logic gets harder to follow.
foo() {
# Note the condition is tested here now
if cond3; then
# do work
fi
}
if cond1; then
if cond2; then
...
else
foo
fi
else
# This code is carefully constructed to ensure that subsequent elifs
# behave correctly
if ! foo; then
# Place the other elifs here
if quux...
这篇关于如果猛砸 - >那么如果 - >否则跳到第一ELIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!