Touch Develop retirement postponed until June 22, 2019. Sign-in and access to cloud assets to be removed on May 23, 2018.Learn More..


for

for is a statement that executes a body of code in a loop.
for 0 i < 10 do
i → post to wall
end for
On each iteration, the loop index i starts at 0 and is incremented by 1 on each iteration until it reaches the loop upper bound. So in the example above, i takes the value of 0, 1, 2, ... and finally 9.

example: computing a sum

A typical use of a for loop is to compute a sum of values. In this example, we simply compute the sum of numbers from 0 to 9. To implement such program, you start by declaring a local variable before the for loop to hold the sum value.
var sum := 0
Then, you would accumulate the values by adding to sum on each iteration.
for 0 j < 10 do
sum := sum + j
end for
Once the loop is finished, the sum is the value of sum.
sum → post to wall