© Tyl Software Foundation 2019-2021
▶ LOOPING BY INDEX
Looping by index is the repeating of code execution for a set number of times.
Looping by index signature:
Consider this code:
Looping by index signature:
[INDEX] [RANGE] ~
Consider this code:
sum 0
index 4 ~
num index + 1
sum ++ num
print sum
^
1
3
6
10
3
6
10
In line '
In the repeat block,
The above looping statement can be written in one line:
index 4 ~
', index
will be a local numeric variable of
the looping statement, and the value 4, is the upper limit. The index will get
the numbers from zero until 4 (not including 4): 0, 1, 2, 3.
In the repeat block,
index
variable will be used, and each time it will have
a different value. The code in the repeat block is summing the numbers 1, 2, 3, 4.
The above looping statement can be written in one line:
sum 0
index 4 ~ print sum ++ index + 1
Average Calculator:
sum 0
numberslen 4
index numberslen ~ sum ++ index + 1
print sum / numberslen
2.5