[ top | up ]

Iterate over a Sequence

Syntax

for(var in seq) expr

Description

seq can be any sequence, i.e. either a list or a vector. The expression expr is executed once for each element of sequence. var is the dummy variable whose value changes for each step. When the iteration is finished var exists and has value equal to the last value attained in the iteration. If a break statement is encountered processing of the loop ceases and execution proceeds with the next statement after the

See Also

while, repeat, next, break.

Examples

for(i in 1:5) print(1:i)