next up previous contents index
Next: A loop with while Up: Loops: Previous: A loop with repeat   Contents   Index


A loop with for

for assign to a variable some successive values in a fixed range with a choosen increment.here is the syntax:
for list1 list2
List1 contains three arguments: the variable name, the start value, the end value.
A fourth argument is optionnal representing the increment( the step between two successive values). Default value is 1. Here are a few examples:
for [i 1 4][pr :i*2]
2
4
6
8

# Now, i is going from 7 to 2 falling down of 1.5 each times
# Look at the negative increment
# Then, Displays its square.

for [i 7 2 -1.5 ][pr list :i power :i 2]
 
7 49
5.5 30.25
4 16
2.5 6.25



Loïc 2008-06-08