Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Import Macro Repair
Panel
bgColor#ffffff
titleQ

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

Panel
bgColor#ffffff
titleA

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.

Panel
bgColor#ffffff
titleSee also...

Filter by label (Content by label)
showLabelsfalse
spaces@self
showSpacefalse
operatorAND
cqllabel = "netscript" and label = "variable" and space = currentSpace ( )
labelsnetscript variable