Re: Return from nested subroutines (still goto discussion)
- Posted by "Michelle Rogers" <michellerogers at bellsouth.net> Nov 12, 2004
- 538 views
You know...this discussion reminds me of a scenario like this. ADVERTISEMENT: All new butter knives! For sale! Slices butter like never before! You'll have butter sliced in record time! This new tool should reduce your butter slicing time by one-half! Because of it's unique design, it is also easier to use than any other butter knife! Hurry while supplies last! Only $1.99! However, you do have to sign a contract that states that you will never use this butter knife as a screwdriver, since we, the manufacturers, did not make it to be used as a butter knife. If you refuse to sign the contract, we will not sell the butter knife to you. ADVERTISEMENT Bottom Line: Don't limit someone else's creativity just because it's not the way you want things done. It doesn't hurt you one bit if someone else uses that butter knife as a screwdriver. And, if you question the safety of some machine that has had the screws put in place with the butterknife...then just don't use that machine. In a capitalistic world, the person will stop using the butter knife if there is no demand for it. On the other hand, if it produces demand, even against the way you think it should, don't be jealous of that demand and find ways to question it. Instead, make a better product. It's called competition. Michelle Rogers ----- Original Message ----- From: "Juergen Luethje" <j.lue at gmx.de> To: <EUforum at topica.com> Sent: Friday, November 12, 2004 5:39 AM Subject: Re: Return from nested subroutines (still goto discussion) > > > aku saya wrote: > > <snip> > > > Thank you, but... > > > > Maybe my code was too much simplified. What I meant is algorithms such > > as backtracking or permutation. Now modified example: > > > > 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 ok > > end if > > else > > for i = 0 to 3 do > > r(x+1, i) > > end for > > end if > > end procedure > > > > procedure main() > > for i = 0 to 3 do > > r(1, i) > > end for > > ok: > > puts(1, "program end") > > end procedure > > > > > > Now the purpose of the program is to search d so that sum(d) = 10 and > > every element of d is from 0 to 3. But when a solution is found, it > > will just print the first solution found and continue to printing > > "program end". > > > > Now how can it modified to use no GOTO and no decrease on performance? > > (using flags to indicate whether a solution has been found would > > decrease performance, I think) > > If I'm right, performance is not the main question here. > Using GOTO this way, i.e. jumping out of procedures will corrupt the > stack, no? So this should not be done anyhow, should it? Please correct > me if I'm wrong. > > Regards, > Juergen > > > >