Is a chained if-elseif conditional check proceeding all checks always independent if one check is true?

Q

Is a chained if-elseif conditional check proceeding all checks always independent if one check is true?

A

No, the netSCRIPT interpreter optimizes.

A sequence of if-elseif inquiries like below will be left with the first met condition, the rest will be bypassed.


if mystate == nil then
-- script is in init state
MY_STATE_INIT_DONE, MY_STATE_1, MY_STATE_2 = 1,2,3
…
mystate = MY_STATE_INIT_DONE
-- script is in running state
elseif mystate == MY_STATE_INIT_DONE then
…
mystate = MY_STATE_1
elseif mystate == MY_STATE_1 then
…
mystate = MY_STATE_1
elseif mystate == MY_STATE_2 then
…
mystate = MY_STATE_INIT_DONE
end

The script execution will be slightly faster, if conditions that are more likely to happen are being placed at the top in such a sequence.