how to increase the variable in a loop in TCL? -
i have following code in tcl:
set counter 1 {set 0} {$i < 3} {incr 1} { set temp $counter incr temp 1 incr counter 2 }
for each loop, counter
increased 2, , temp
increased 1 based on value of counter
, value of counter
, temp
is:
counter 1 temp 2 in first loop counter 3 temp 3 in second loop counter 5 temp 4 in third loop
the expected value is:
counter 1 temp 2 in first loop counter 3 temp 4 in second loop counter 5 temp 6 in third loop
what problem , how fix it?
it depends on use value:
set counter 1 {set 0} {$i < 3} {incr 1} { set temp $counter puts "a: counter = $counter, temp = $temp" incr temp 1 puts "b: counter = $counter, temp = $temp" incr counter 2 puts "c: counter = $counter, temp = $temp" }
when run that, get:
a: counter = 1, temp = 1 b: counter = 1, temp = 2 c: counter = 3, temp = 2 a: counter = 3, temp = 3 b: counter = 3, temp = 4 c: counter = 5, temp = 4 a: counter = 5, temp = 5 b: counter = 5, temp = 6 c: counter = 7, temp = 6
it looks me want values position puts "b:…"
located.
Comments
Post a Comment