Search This Blog

TCL: for loop with multiple variables

TCL for loop is in the form of
for { init } { test } { next } { body }
. The examples below shows for loops with more than one variables:
  1. Example 1:
    for { set i 0; set j 10 } { $i < $j } { incr i; incr j -1 } {
       puts "$i $j"
    }
    
    Output:
    0 10
    1 9
    2 8
    3 7
    4 6
    
  2. Example 2:
    for { set i 0; set j 10 } { $i < 3 && $j < 7 } { incr i; incr j -1 } {
       puts "$i $j"
    }
    
    Output:
    0 10
    1 9
    2 8
    

No comments:

Post a Comment