Re: invoked "break" outside of a loop



Russell Trleleaven wrote:
Gerald W. Lester wrote:
Russell Trleleaven wrote:
set numbers [ list 0 1 2 3 4 5 6 7 8 9 ]
proc foo {} {
#return break
#uplevel break
#namespace eval :: break
return -code break
}
foreach number $numbers {
if { $a == 3 } { foo }
puts $a
}

return break in foo gets me "invoked "break" outside of a loop"
uplevel break does the same.
namespace eval :: break does the same.
return -code break does what I want.

Should any of the first three approaches work like the fourth?

Sincerely,

russ@xxxxxxxx

Funny, when I run the above code I get:

can't read "a": no such variable

Now if I run:

proc foo {} {
#return break
#uplevel break
#namespace eval :: break
return -code break
}
foreach a $numbers {
if { $a == 3 } { foo }
puts $a
}

I get:
0
1
2

with no error.

Yes I made an error
Sorry to belabor the point but I was hoping someone would explain why
"break"
"uplevel break"
and
"namespace eval :: break"
don't work like I thought they might.

Maybe if you explained why you would think that they would work we may be able to tell you where you are going wrong.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.



Relevant Pages