Re: Return from nested subroutines (still goto discussion)
- Posted by Derek Parnell <ddparnell at bigpond.com> Nov 12, 2004
- 544 views
unknown wrote: > > > Code.. > (I used to use this in PASCAL long time ago) > > > procedure r(integer x) > if x = 5 then > puts(1, "success") > goto ok > end if > r(x+1) > puts(1, "don't come here!") > end procedure > > procedure main() > r(1) > ok: > puts(1, "program end") > end procedure > > > When main() is executed, it will call r(1), r(1) will call r(2), etc, > r(4) will call r(5), r(5) will print "success" and then goto ok which > will print "program end" without no printing of "don't come here!" > > That is the very convenient use of goto, and I used goto only on > programs like that. > > Is there any method to perform the same as above without goto and > without decreasing performance? > > procedure r(integer x) if x = 5 then puts(1, "success") else r(x+1) end if end procedure procedure main() r(1) puts(1, "program end") end procedure -- Derek Parnell Melbourne, Australia