Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complicated variables

Status
Not open for further replies.

empty84

Programmer
Dec 8, 2006
6
PL
i have some variables :

var1, var2, var3, var4, var5, var6

and i want to "puts" all of this variables in "for" loop:

for {set i 1} {$i<=6} {incr i} {
?puts $var$i
?puts $[var$i]
?puts $"var$i"
}

how can i do that?
 
If you're building names you probably need to use an array:

Code:
 array set var {1 one 2 two 3 three}
 set var(4) four
 foreach name [array names var] \
 { puts $var($name) }
 puts var(1)
 puts var(2)
 puts var(3)

More on array at
HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top