goto を許可しない言語でネストしない条件文をどのように偽造しますか? 私は次のことをしたい:
if (condition1)
action1;
if (!condition1 && condition2)
action2;
if (!condition2 && condition3)
action3;
それなし:
- 不必要に条件を複数回評価する。
- そのような評価の結果を不必要に変数に格納します。
- アクションを実行する必要があることを不必要に複数回指定する。
元のスニペットは要件 1 を満たしていません。
次のスニペットは、要件 2 を満たしていません。
if (condition1) {
action1;
c2 = false;
}
else if (c2 = condition2)
action2;
if (!c2 && condition3)
action3;
また、次のスニペットは要件 3 を満たしていません。
if (condition1) {
action1;
if (condition3)
action3;
}
else if (condition2)
action2;
else if (condition3)
action3;
編集:
condition1
とがcondition2
同時に真であることは不可能です。condition2
とがcondition3
同時に真であることは不可能です。
元のコード (JavaScript) は次のとおりです。
// If only the array of elements was specified,
// wrap it inside an object.
if (info.constructor !== Object)
info = {children: info};
// If no array of elements was specified, create
// an empty array of elements.
if (!info.children)
info.children = [];
// If, instead of an array of elements, we have
// a single element, wrap it inside an array.
if (info.children.constructor !== Array)
info.children = [info.children];