AuthorMessage
Meka][Meka
Unstopable
Posts: 700

EXAMPLES
Print a line for each of the integers from 0 to 10:
Code:

for {set x 0} {$x<10} {incr x} {
   puts "x is $x"
}

Either loop infinitely or not at all because the expression being evaluated is actually the constant, or even generate an error! The actual behaviour will depend on whether the variable x exists before the for command is run and whether its value is a value that is less than or greater than/equal to ten, and this is because the expression will be substituted before the for command is executed.
Code:

for {set x 0} $x<10 {incr x} {
   puts "x is $x"
}

Print out the powers of two from 1 to 1024:
Code:

for {set x 1} {$x<=1024} {set x [expr {$x * 2}]} {
   puts "x is $x"
}