0

Could someone help me to understand why the below code hangs (i.e. stuck in an endless loop) in Xcelium simulator, and what should be the correct one?

for {set i 0} {$i < 2} {incr $i} { puts "i is $i"; }
set i 0
while {$i < 2} { puts "i is $i"; incr $1; }

The result for either for or while loop above is just an endless: i is 0

renvill
  • 143
  • 1
  • 10

1 Answers1

1

incr takes a variable name as input argument, so it should be incr i.

incr $i increments instead the variable 0. What happens if the variable does not exist depends on Tcl version. From the manual page:

Starting with the Tcl 8.5 release, the variable varName passed to incr may be unset, and in that case, it will be set to the value increment or to the default increment value of 1.

Andreas
  • 5,086
  • 3
  • 16
  • 36