while TEST BODY |
|
(Because, you may inadvertantly write infinite loops !)
set x 0 while {$x < 10} { puts "x is $x" set x [expr {$x + 1}] } puts "exited loop with x equal to $x\n" |
set x 0 while "$x < 10" { puts "x is $x" set x [expr {$x + 1}] }====> infinite loop !!! |
(See above for the actual TEST string that is passed to WHILE for testing)
for START TEST NEXT BODY |
|
Yes, you guessed it, you better use { ... } to prevent substitutions in all the parts |
(Because, you may inadvertantly write infinite loops !)
Java equivalent: for (i = 0; i < 9; i = i + 1) for {set i 0} {$i < 10} {set i [expr $i + 1]} { puts "i = $i" } |
incr VARNAME [increment-amount] Examples: incr i i = i + 1 incr i 2 i = i + 2 |
Java equivalent: for (i = 0; i < 9; i = i + 1) for {set i 0} {$i < 10} {incr i} { puts "i = $i" } |