在C语言中,可以使用级联switch语句轻松实现此流程:
switch (var) {
case c: C();
case b: B();
case a: A();
default: // no op
}
是否有其他编程语言可以支持此流程?例如。在 Python、Java 中?
最佳答案
您可以使用任何具有 if 语句和逻辑 OR 运算符(这将是全部)的语言来支持该流程
flow = 0;
if ( var == a ) {
A();
flow = 1;
}
if ( flow || var == b ) {
B();
flow = 1;
}
if ( flow || var == c ) {
C();
flow = 1;
}
// and so on
关于java - 适合什么控制流程 "if A, then do a; if B, then do a, b; if C, then do a, b, c ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28792264/