1. goto and label
- Posted by Lnettnay Jun 28, 2022
- 810 views
Trying to test the following program from November 2004 https://openeuphoria.org/forum/28873.wc?last_id=28875
object d d = {0,0,0,0,0} procedure r(integer x, integer y) d[x] = y if x = 5 then if d[1]+d[2]+d[3]+d[4]+d[5] = 10 then puts(1, "success") -- (print d here) goto "okay" end if else for i = 0 to 3 do r(x+1, i) end for end if end procedure for i = 0 to 3 do r(1, i) end for label "okay" puts(1, "program end")
And I get the following error
<0156>:: Unknown label 'okay' goto "okay" ^
What am I doing wrong?
Lonny
2. Re: goto and label
- Posted by ChrisB (moderator) Jun 29, 2022
- 803 views
Hi
Lookks like you're jumping outside the scope of the procedure r(). goto's should should really only be restricted to use within a procedure or function (or called and labelled outside the scope of either, like your 'for' loop)
It's permissable (I think) to got from inside a for loop, but very bad practice. exit instead.
Cheers
Chris
3. Re: goto and label
- Posted by ghaberek (admin) Jun 29, 2022
- 793 views
Lookks like you're jumping outside the scope of the procedure r(). goto's should should really only be restricted to use within a procedure or function (or called and labelled outside the scope of either, like your 'for' loop)
It's permissable (I think) to got from inside a for loop, but very bad practice. exit instead.
That is correct. The docs specifically state it as such. (Emphasis mine.)
4.6.6 goto statement
goto instructs the computer to resume code execution at a place which does not follow the statement. The place to resume execution is called the target of the statement. It is restricted to lie in the current routine, or the current file if outside any routine.
I think the intent was to prevent wild "spaghetti code" that could jump around, as I put it back then, "all willy-nilly."
Trying to test the following program from November 2004 https://openeuphoria.org/forum/28873.wc?last_id=28875
object d d = {0,0,0,0,0} procedure r(integer x, integer y) d[x] = y if x = 5 then if d[1]+d[2]+d[3]+d[4]+d[5] = 10 then puts(1, "success") -- (print d here) goto "okay" end if else for i = 0 to 3 do r(x+1, i) end for end if end procedure for i = 0 to 3 do r(1, i) end for label "okay" puts(1, "program end")
And I get the following error
<0156>:: Unknown label 'okay' goto "okay" ^
What am I doing wrong?
That thread is from 2004 and goto wasn't finalized until Euphoria 4.0, which came out in 2008. The feature you're trying to use here simply does not exist.
-Greg
4. Re: goto and label
- Posted by Lnettnay Jun 29, 2022
- 782 views
Thanks guys. I thought it was probably something simple.
Lonny