我正在研究Node.js中的一些代码。基本上我正在尝试分析和应用URL的查询部分的逻辑。我的情况摘要如下:
If(condition1){run1};
If(condition2){run2};
else{run3};
当F-F(condition1-condition2)run3发生时 当T-F run3发生时(run1应该发生......) 当F-T run2发生时 当T-T run1和run2发生时
我试过了:
If(condition1){run1};
else{run4};
If(condition2){run2};
else{run3};
其中run4为空白。
这里发生了什么?我希望run1在满足条件1时发生,如果满足条件2则运行,如果两者都满足则运行,如果不满足则都不运行。
TIA
答案 0 :(得分:3)
if (condition1) {
run1;
}
if (condition2) {
run2;
}
if (! condition1 && ! condition2) {
run3;
}
答案 1 :(得分:-2)
以下是带正确括号的正确解决方案
If(condition1){run1};
If(condition2){run2};
If(!condition2 && !condition2){run3};