Re: invoked "break" outside of a loop



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.
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.



Relevant Pages