与fallthrough开关的情况下? [英] Switch case with fallthrough?
本文介绍了与fallthrough开关的情况下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要寻找switch语句的正确的语法与fallthrough案件击(如果最好的是不区分大小写)。
在PHP中我会编程,它像:
I am looking for the right syntax of the switch statement with fallthrough cases in Bash (the best if it is case-insensitive). In PHP I would program it like:
switch($c) {
case 1:
do_this();
break;
case 2:
case 3:
do_what_you_are_supposed_to_do();
break;
default:
do_nothing();
}
我想在猛砸相同的:
I want the same in Bash:
case "$C" in
"1")
do_this()
;;
"2")
"3")
do_what_you_are_supposed_to_do()
;;
*)
do_nothing();
;;
esac
这在某种程度上不起作用:函数 do_what_you_are_supposed_to_do()
当$ C是应该被解雇2或3。
This somehow doesn't work: function do_what_you_are_supposed_to_do()
should be fired when $C is 2 OR 3.
推荐答案
使用一个竖线或
case "$C" in
"1")
do_this()
;;
"2" | "3")
do_what_you_are_supposed_to_do()
;;
*)
do_nothing()
;;
esac
这篇关于与fallthrough开关的情况下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文