For statement

A for statement is used to loop over a list of values, executing statements each time.

for variable in list do statement
for variable in list  /* optional "do" here */
    statements
end
for key = variable in list do statement
for key = variable in list  /* optional "do" here */
    statements
end

In the for statement, variable is set to a value from the list each time statements are executed. When specified, key is set to the key of that value in the list. If list is actually not a list but a different type of value, the statements are executed only once with variable set to that value.

The for statement may have an else clause and break and continue statements, just as the while statement.

Yewslip> factorial = 1

Yewslip> n = 5

Yewslip> for i in [1:n+1]
    ...>     factorial *= i
    ...> end

Yewslip> print factorial
120