I have the following basic code:
proc test {} {
set my_var2 3
foreach iter {1 2 3} {
set my_var1 4
set my_var2 5
puts "Inside: $my_var1 $my_var2
"
}
puts "outside $my_var1, $my_var2
" ;#WHY IT DOES NOT GIVE ERROR HERE!
}
test ;#calling the function
该方案的产出是:
Inside: 4 5
Inside: 4 5
Inside: 4 5
outside 4, 5
Now my confusion is since my_var1
is define only in the local scope of foreach loop why its value is available even outside the loop? In other words what determines the scope of a variable in Tcl?
Thanks a lot for the help!