How can i access below code in tcl -


i want values of ya0,ya1 using loop.
below code not working.

set ya0 12   set ya1 16   {set 0}  {$i < 2} {incr i} {   puts "$ya{$i}"   }     

you're there.

set ya0 12   set ya1 16   {set 0} {$i < 2} {incr i} {       puts [set ya$i] }   

this simpler might not applicable in code:

set ya0 12   set ya1 16   foreach varname {ya0 ya1} {     puts [set $varname] } 

in both cases, set command used value variable name isn't known until runtime.

if want construct variable names root (ya) , variable suffix/index (0, 1, ...), array can useful:

set ya(0) 12   set ya(1) 16   {set 0} {$i < 2} {incr i} {       puts $ya($i) }   

sometimes when 1 this, 1 wants list:

set ya [list 12 16] {set 0} {$i < 2} {incr i} {       puts [lindex $ya $i] } # or (better) foreach val $ya {     puts $val } 

documentation: for, foreach, incr, lindex, list, puts, set, variable substitution


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -