Name

for — For loop.

Synopsis

for initialization test step body

Description

The for command is like in many other languages like C and Java. As arguments, it takes an initialization option, which is often used to set a variable to some initial value, a test to determine whether to continue running, a step script option which is run at each iteration of the body (to increment a variable, for example), and the body itself.

Example

set out {}
for {set i 0} {< $i 10} {incr $i} {
    append $out $i
}
puts $out
	  

Produces:

0123456789