Flow control – Multichannel Systems NeuroExplorer User Manual

Page 139

Advertising
background image

5.4. Flow Control

Loops


NexScript supports two types of loops: for loops and while loops.


for loop has the following syntax:

for variable = expression to expression

statements ...

end


Example:

for i = 1 to 10

SelectVar(doc, i, "neuron")

end



while loop has the following syntax:

while logical_expression

statements ...

end


Example:

i = 1

while i < 10

SelectVar(doc, i, "neuron")

i = i + 1

end

break


break statement causes an immediate exit from the loop.


The following loop

for i = 1 to 10

Trace(i)

if i == 5

break

end

end


will produce output: 1 2 3 4 5

continue


continue statement returns to the loop’s beginning skipping the statements that follow it.


The following loop

for i = 1 to 5

if i == 3

continue

end

Trace(i)

end


will produce output: 1 2 4 5

return


return statement causes an immediate exit from the script.


Page 137

Advertising