Loops in Igor Pro
for and do-while, and the reminder that a wave assignment usually beats both.
Function SumPositive(WAVE w)
Variable i, total = 0
for (i = 0; i < numpnts(w); i += 1)
if (w[i] <= 0)
continue
endif
total += w[i]
endfor
return total
End
Function CountDown(Variable n)
do
n -= 1
while (n > 0)
return n
End
How it works
fortakes the C shape and closes withendfor.docloses withwhile, so the body always runs once.breakleaves the loop;continuejumps to the next turn.
Keywords and builtins used here
EndFunctionVariableWAVEcontinuedoendforendifforiifnumpntsreturnwhile
The run, in numbers
- Lines
- 19
- Characters to type
- 225
- Tokens
- 69
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 55 seconds.
Step 2 of 4 in Flow control, step 9 of 18 in Language basics.