1. goto's, and loops
- Posted by Kat <KSMiTH at PELL.NET> Jul 29, 1999
- 620 views
Hi all, Why is there no "goto" in Euphoria? It would be easy enough to implement, and if you don't want to use it, you don't haveto. I've used it sparingly in other languages, for the example below, for example. Maybe i am in a rut, but i don't see an nice way to do this example in Euphoria, can you help, please? ( Without making another procedure and all the vars global. ) loop1 some code loop2 test var, maybe goto target -- an "exit" here would get you out of loop2, not loop1 EndOfLoop1 more code EndOfLoop2 :target thanks, Kat
2. Re: goto's, and loops
- Posted by JJProg at CYBERBURY.NET Jul 29, 1999
- 545 views
EU>Hi all, EU>Why is there no "goto" in Euphoria? It would be easy enough to implement, EU>and if you don't want to use it, you don't haveto. I've used it sparingly in EU>other languages, for the example below, for example. Maybe i am in a rut, EU>but i don't see an nice way to do this example in Euphoria, can you help, EU>please? ( Without making another procedure and all the vars global. ) EU>loop1 EU>some code EU>loop2 EU>test var, maybe goto target EU>-- an "exit" here would get you out of loop2, not loop1 EU>EndOfLoop1 EU>more code EU>EndOfLoop2 EU>:target EU>thanks, EU>Kat Gotos allow spagetti-code. It's much more elegant to use procedures and functions, and it is also easier to debug. Jeffrey Fielding JJProg at cyberbury.net http://members.tripod.com/~JJProg/
3. Re: goto's, and loops
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Jul 29, 1999
- 544 views
Hello, Kat you wrote: >Hi all, > >Why is there no "goto" in Euphoria? It would be easy enough to implement, >and if you don't want to use it, you don't haveto. I've used it sparingly >in >other languages, for the example below, for example. Maybe i am in a rut, >but i don't see an nice way to do this example in Euphoria, can you help, >please? ( Without making another procedure and all the vars global. ) > >loop1 >some code >loop2 >test var, maybe goto target >-- an "exit" here would get you out of loop2, not loop1 >EndOfLoop1 >more code >EndOfLoop2 >:target > >thanks, >Kat well I could do this easily with a routine but lets try this: integer i i = 0 while x do -- loop1 ..some_code.. while y do -- loop 2 if test_var then exit end if if want_out_of_loop_2 then i = 1 end if end while -- end of loop 2 if i then exit end if ..more_code.. end while -- end of loop 1 ..target.. hope this helps, Lewis Townsend _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com
4. Re: goto's, and loops
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Jul 29, 1999
- 547 views
Kat wrote: > Maybe i am in a rut, but i don't see an nice way > to do this example in Euphoria, can you help, > please? You could write: continue = 1 while loop1 and continue do some code while loop2 do if test var then continue = 0 exit end if more code end while end while Or perhaps: exitFlag = 0 while loop1 do some code while loop2 do if test var then exitFlag = 1 exit end if more code end while if exitFlag then exit end if end while -- David Cuny
5. Re: goto's, and loops
- Posted by Derek Parnell <dparnell at BIGPOND.NET.AU> Jul 30, 1999
- 553 views
Another language I use, Progress 4GL, has a specialized variety of goto. It uses the syntax "leave <blockname>" . Your example would be coded thus... loop1: repeat: some code loop2: repeat: if var then leave loop1. end. /* of loop2 */ more code end. /* of loop 1 */ The idea of named blocks of code might not be too difficult it add to Euphoria, however name-space issues might arise. cheers, Derek Parnell dparnell at bigpond.net.au Melbourne, Australia
6. Re: goto's, and loops
- Posted by Irv Mullins <irv at ELLIJAY.COM> Jul 29, 1999
- 551 views
On Thu, 29 Jul 1999, you wrote: > Hi all, > > Why is there no "goto" in Euphoria? It would be easy enough to implement, > and if you don't want to use it, you don't haveto. I've used it sparingly in > other languages, for the example below, for example. Maybe i am in a rut, > but i don't see an nice way to do this example in Euphoria, can you help, > please? ( Without making another procedure and all the vars global. ) Let's see what you've written: > loop1-------------- > something | > loop2 -------------|--------- > test var, maybe goto | | > -- an "exit" | | > EndOfLoop1---------- | > more code | > EndOfLoop2------------------ > :target Follow the lines. That's why 1. you don't see gotos' in all languages, and 2. you get a D on the assignment, unless you can find a real life example where this construct works under all test conditions, and cannot be replaced with simpler, properly nested code.. Irv
7. Re: goto's, and loops
- Posted by Roderick Jackson <rjackson at CSIWEB.COM> Jul 29, 1999
- 554 views
Hi Kat, If I read Rob (and the language) correctly, one of the guiding principles of Euphoria is that a programmer shouldn't do something that others (or he himself, later on) will find extremely difficult to understand, debug or change. This is part of "the Euphorian philosopy" of coding, language design, and programming in general. Now, I've seen examples where gotos have been used in code without being at all troublesome, fitting cleanly in the algorithm. But, the potential for abuse with the goto statement is absolutely monstrous. Sure, it CAN be used well; but remember the Euphorian philosophy. When I was introduced to the concept of structured programming (while using BASIC), I started trying to NOT use gotos, and it helped my coding. It was easier for me to remember what my code did, and it helped organize my code into logical subsections. Rob's decision to leave out the goto does have a number of advantages, and fits with the Euphorian philosophy. Since using QBasic and becoming more experienced with program flow, I haven't missed it. It might take some getting used to, but you'll find that anything that can be done with a goto can be done without; of course, in some cases the goto is just plain easier to use. As to your example... the short answer would be "redesign the algorithm," but that's not always desireable. One specific approach would be to leave the code pretty much the way it is, but use local variables to store certain states. The result would look something like: ConditionFlag = 0 -- this is FALSE for i = w to x do -- some code for j = y to z do if (s[i][j] = 0) then ConditionFlag = 1 -- this is TRUE exit end if end for if (not (ConditionFlag)) then -- more code end if end for Hope this helps you out some... Rod ---------- From: Kat[SMTP:KSMiTH at PELL.NET] Sent: Thursday, July 29, 1999 10:49 AM To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: goto's, and loops Hi all, Why is there no "goto" in Euphoria? It would be easy enough to implement, and if you don't want to use it, you don't haveto. I've used it sparingly in other languages, for the example below, for example. Maybe i am in a rut, but i don't see an nice way to do this example in Euphoria, can you help, please? ( Without making another procedure and all the vars global. ) loop1 some code loop2 test var, maybe goto target -- an "exit" here would get you out of loop2, not loop1 EndOfLoop1 more code EndOfLoop2 :target thanks, Kat
8. Re: goto's, and loops
- Posted by Irv Mullins <irv at ELLIJAY.COM> Jul 29, 1999
- 544 views
Hmm.. doesn't look so good with a monospaced font: I'll try again: > > loop1--------------1 > > something > > loop2 ----------------------2 > > test var, maybe goto > > -- an "exit" > > EndOfLoop1----------1 > > more code > > EndOfLoop2------------------2 > > :target Irv
9. Re: goto's, and loops
- Posted by Kat <KSMiTH at PELL.NET> Jul 29, 1999
- 553 views
----- Original Message ----- From: Irv Mullins <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, July 29, 1999 12:58 PM Subject: Re: goto's, and loops > On Thu, 29 Jul 1999, you wrote: > > Hi all, > > > > Why is there no "goto" in Euphoria? It would be easy enough to implement, > > and if you don't want to use it, you don't haveto. I've used it sparingly in > > other languages, for the example below, for example. Maybe i am in a rut, > > but i don't see an nice way to do this example in Euphoria, can you help, > > please? ( Without making another procedure and all the vars global. ) > > Let's see what you've written: > > > loop1-------------- > > something | > > loop2 -------------|--------- > > test var, maybe goto | | > > -- an "exit" | | > > EndOfLoop1---------- | > > more code | > > EndOfLoop2------------------ > > :target > > Follow the lines. That's why > 1. you don't see gotos' in all languages, and > 2. you get a D on the assignment, > unless you can find a real life example where this construct works under all > test conditions, and cannot be replaced with simpler, properly nested code.. /me looks all over for the aforementioned code that Irv wrote.. Ooops, i just threw that together, with the EndOfLoop1 and EndOfLoop2 swapped. But assuming i hadn't swapped them ( ie they were correctly placed ), i don't see anything easier than David Cuny's code (thanks, David) which used 2x as much screen space,, so a "goto" would have been easier and prolly faster to execute. Granted that goto's *can* lead to spagetti code, but they don't *force* you to write spagetti code. The lack of a goto can lead to setting and testing and clearing exit variables. If we must use exit variables in nested loops, this seems to say that there is no point in using "while" (which test their var at the top of the loop) or "for" loops when nesting, just use infinite loops ("if true then") and "exit"s,, `cause you use the exit var anyways, hmm, i could get addicted to exit vars.. where "exit" substitutes for a "goto -- remark at end of this loop". Ok, what about "repeat-until" loops? I didn't see them in Euphoria either. It's a "while-do" loop with the test at the end instead of the beginning. Yes, there are ways around most, if not all, things missing in a language, but a simple *local* goto, which wouldn't leave the procedure or function it is in, would be nice. In my humble opinion. If there was a vote i missed or anything... etc.. Kat
10. Re: goto's, and loops
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Jul 29, 1999
- 522 views
Kat wrote: > Ok, what about "repeat-until" loops? repeat code here until test would be: while 1 do code here if test then exit end if end while Hope you like the one-line if statement. -- David Cuny
11. Re: goto's, and loops
- Posted by "Boehme, Gabriel" <gboehme at POBOXB1.HQ.MSMAIL.MUSICLAND.COM> Jul 29, 1999
- 538 views
Kat wrote: >Why is there no "goto" in Euphoria? It would be easy enough to implement, >and if you don't want to use it, you don't haveto. The "if you don't want to use it, you don't have to" argument has been beaten to death here on the list by people proposing all sorts of things, both good and bad. It's an extremely weak argument, easily countered by "well, if we don't *have* to use it, we don't need it." And neither of these arguments has anything to do with the actual idea in question -- they're merely simplistic appeals to either add a new feature, just because; or not to add a new feature, just because. > I've used it sparingly in >other languages, for the example below, for example. Maybe i am in a rut, >but i don't see an nice way to do this example in Euphoria, can you help, >please? ( Without making another procedure and all the vars global. ) > >loop1 >some code >loop2 >test var, maybe goto target > -- an "exit" here would get you out of loop2, not loop1 >EndOfLoop1 >more code >EndOfLoop2 >:target Just from glancing at it, I'd say the logic is in need of some revision. Here's my Euphorish pseudo-code version of what you have here: -------- while 1 do some code while 2 do if condition then goto target end if end while more code end while :target -------- The above example begs the following questions: why one loop inside of another? Why have code both above and below this second loop, when it's inside a while? Without actual code to fill in the example, it looks rather artificial, not something one would actually code for real. Despite your restriction that I not create another function, I'm going to say that that's exactly what you need in this situation. I've found it's almost always a bad idea to code one while loop inside another, no matter what language you're using. Far better to code the second, nested while loop in its own function. This forces you to decide which variables specifically apply to only the nested loop, and it helps make things more understandable later on. -------- function meaningful_name(object parms) while 1 do if condition then return 1 -- stop everything! end if end while return 0 -- keep going end function while 1 do some code if meaningful_name(parms) then exit end if more code end while -- target -------- This works quite nicely without cluttering up the code too much. As you can see, however, it's very difficult to come up with a nice, readable solution without a specific idea of what's trying to be accomplished here. Again, your example seems very artifical to me, as though it exists for no other reason than to make your point about goto's seem valid. Please feel free to prove me wrong -- give us a *specific* code example which you feel illustrates the absolute *need* for goto's. Be seeing you, Gabriel Boehme
12. Re: goto's, and loops
- Posted by Roderick Jackson <rjackson at CSIWEB.COM> Jul 29, 1999
- 527 views
Kat wrote: >Ok, what >about "repeat-until" loops? I didn't see them in Euphoria either. It's a >"while-do" loop with the test at the end instead of the beginning. Yes, >there are ways around most, if not all, things missing in a language, but a >simple *local* goto, which wouldn't leave the procedure or function it is >in, would be nice. In my humble opinion. If there was a vote i missed or >anything... etc.. You'll probably be shocked to hear this, but originally there wasn't even a "for..next" loop in Euphoria--just "while..do"! From what I gather, earlier on Euphoria had an even stronger "minimalist" approach than now: only commands that were necessary, no redundancy. And since "for..next" can be emulated with a "while" loop, it wasn't part of the language. Honestly though, I think the addition of "for" was a good one; it added some redundancy, but with good reason. I'm not sure I could make a good case for adding the "repeat..until" loop though... And I agree with you that a local goto would be nice. But I think not allowing it is the better option. Just my opinion. Rod
13. Re: goto's, and loops
- Posted by Jason Gade <jgade at PCEZ.COM> Jul 29, 1999
- 539 views
- Last edited Jul 30, 1999
Although I haven't worked on the program for awhile, I wondered about goto's when trying to port the Rogue role-playing game from C to Euphoria as an exercise. Here is the original code: main(argc, argv) int argc; char *argv[]; { /* Save the setuid we have got, then turn back into the player */ saved_uid=geteuid(); setuid(true_uid=getuid()); if (init(argc, argv)) { /* restored game */ goto PL; } for (;;) { clear_level(); make_level(); put_objects(); put_stairs(); add_traps(); put_mons(); put_player(party_room); print_stats(STAT_ALL); PL: play_level(); free_stuff(&level_objects); free_stuff(&level_monsters); } } Notice the goto jumping into the middle of the loop so that the program can handle a new game or a resumed game. Now, here is the Euphoria. Although it took me some figuring out, I think that it is clearer than the C version. If anyone has a better way of doing it, though, I am willing to learn. -- main() if init(command_line()) then -- restored game play_level() free_stuff(&level_objects) -- Note: didn't translate this yet! free_stuff(&level_monsters) -- Ditto! end if while TRUE do -- main loop BEGIN clear_level() make_level() put_objects() put_stairs() add_traps() put_mons() put_player(party_room) print_stats(STAT_ALL) play_level() free_stuff(&level_objects) -- didn't translate free_stuff(&level_monsters) -- ditto end while -- main loop END -- end main() Gee, I need to get back to work on this . . . The hardest part is figuring out all of the dependencies so that I can include stuff in the right order. I guess that I just have to make a chart by hand, but if anyone has any other useful tips they will be welcome.
14. Re: goto's, and loops
- Posted by Bernie Ryan <bwryan at PCOM.NET> Jul 30, 1999
- 520 views
On Thu, 29 Jul 1999 21:35:24 -0700, Jason Gade <jgade at PCEZ.COM> wrote: >Although I haven't worked on the program for awhile, I wondered about goto's >when trying to port the Rogue role-playing game from C to Euphoria as an >exercise. Here is the original code: > >main(argc, argv) >int argc; >char *argv[]; >{ > /* Save the setuid we have got, then turn back into the player */ > saved_uid=geteuid(); > setuid(true_uid=getuid()); > > if (init(argc, argv)) { /* restored game */ SET NEW GAME FLAG > goto PL; > } > > for (;;) { IF ( NEW GAME ) { > clear_level(); > make_level(); > put_objects(); > put_stairs(); > add_traps(); > put_mons(); > put_player(party_room); > print_stats(STAT_ALL); } >PL: > play_level(); > free_stuff(&level_objects); > free_stuff(&level_monsters); > } >} Bernie
15. Re: goto's, and loops
- Posted by "Lucius L. Hilley III" <lhilley at CDC.NET> Jul 30, 1999
- 563 views
WARNING: Pseudo-code follows. A goto statement has two uses. 1. skip code. integer h -- file handle h = open("somefile", "r") if h = -1 then --file not opened goto Skip end if load_opened_file() :Skip do_other_things() 2. repeat code. :Repeat puts(1, "This keeps printing...") goto Repeat Skip code can be accomplished with of the following if statements. if flag then do_code() end if if flag then do_code() else do_other_code() end if if flag1 then do_code1() elsif flag2 then do_code2() end if if flag1 then do_code1() elsif flag2 then do_code2() else do_other_code() end if Repeat code is handled with a while loop. while 1 do do_code() if exit_now then exit end if do_more_code() end while the exit can be placed anywhere and will only exit that loop. The only way to exit nested loops is with flags for each loop. integer end_loop1, end_loop2, end_loop3 end_loop1 = repeat(0, 3) while 1 do --loop1 while 1 do --loop2 while 1 do --loop3 end_loop1 = 1 exit end while --end_loop3 if end_loop1 or end_loop2 then exit end if end while --end_loop2 if end_loop1 then exit end if end while --end_loop1 Lucius L. Hilley III lhilley at cdc.net lucius at ComputerCafeUSA.com +----------+--------------+--------------+----------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | Computer | | Horse +--------------+--------------+ Cafe' | | Software | http://www.cdc.net/~lhilley | USA | +----------+-------+---------------------+----------+ | http://www.ComputerCafeUSA.com | +--------------------------------+
16. Re: goto's, and loops
- Posted by "C. K. Lester" <cklester at TICNET.COM> Jul 30, 1999
- 536 views
You know, I bet it would be real easy if someone wanted to write a Case statement function... case( testVar, { {Case of 1, result}, {Case of 2, result}, {Case of n, result} } ) where testVar is the value to be tested, "Case of x" is the value to be compared, and "result" is the procedure ID or code to be run when the case matches. For instance: myVar = 10 case( myVar, { {1, aFunction}, {2, bFunction}, {">3 AND <10", cFunction}, {">10", dFunction} } ) case would probably need to be able to handle atoms or sequences (as above) to handle everything. At 12:15 PM 7/30/99 -0400, you wrote: >WARNING: Pseudo-code follows. > >A goto statement has two uses. > >1. skip code. > > integer h -- file handle > h = open("somefile", "r") > if h = -1 then --file not opened > goto Skip > end if > load_opened_file() > > :Skip > do_other_things() > >2. repeat code. > > :Repeat > puts(1, "This keeps printing...") > goto Repeat > > >Skip code can be accomplished with of the following if statements. > if flag then > do_code() > end if > > if flag then > do_code() > else > do_other_code() > end if > > if flag1 then > do_code1() > elsif flag2 then > do_code2() > end if > > if flag1 then > do_code1() > elsif flag2 then > do_code2() > else > do_other_code() > end if > >Repeat code is handled with a while loop. > > while 1 do > do_code() > if exit_now then > exit > end if > do_more_code() > end while > >the exit can be placed anywhere and will only exit >that loop. The only way to exit nested loops is with >flags for each loop. > >integer end_loop1, end_loop2, end_loop3 > >end_loop1 = repeat(0, 3) > >while 1 do --loop1 > while 1 do --loop2 > while 1 do --loop3 > end_loop1 = 1 > exit > end while --end_loop3 > if end_loop1 or end_loop2 then > exit > end if > end while --end_loop2 > if end_loop1 then > exit > end if >end while --end_loop1 > > > > Lucius L. Hilley III > lhilley at cdc.net lucius at ComputerCafeUSA.com >+----------+--------------+--------------+----------+ >| Hollow | ICQ: 9638898 | AIM: LLHIII | Computer | >| Horse +--------------+--------------+ Cafe' | >| Software | http://www.cdc.net/~lhilley | USA | >+----------+-------+---------------------+----------+ > | http://www.ComputerCafeUSA.com | > +--------------------------------+
17. Re: goto's, and loops
- Posted by Bernie Ryan <bwryan at PCOM.NET> Jul 30, 1999
- 544 views
This is a response to a question I asked about case statment. from david. Bernie ____________________________________________________________________________ _ Bernie Ryan wrote: > Using a sequence of routine id's to make a case (switch) > statement. Here's a case statement: select case of a: case 1: foo() case 2: bar() case 3: grill end select Here's the same code as an if statement: if a = 1 then foo() elsif a = 2 then bar() elsif a = 3 then grill() end if Here's the same code using routine_id: constant switch = { routine_id("foo"), routine_id("bar"), routine_id("grill") } if a = 1 then call_proc( switch[1], {} ) elsif a = 2 then call_proc( switch[2], {} ) elsif a = 3 then call_proc( switch[3], {} ) end if The pattern in the if statement should be painfully obvious: constant switch = { routine_id("foo"), routine_id("bar"), routine_id("grill") } if a > 0 and a <= length( switch ) then call_proc( switch[a], {} ) end if Or you could use my handy-dandy in_range() function to make the code a bit cleaner: if in_range( a, s ) then call_proc( switch[a], {} ) end if Sorry, couldn't resist. You can also write a switch procedure: procedure switch( integer i, sequence s ) if i > 0 and i <= length( s ) then call_proc( s[i] ) end procedure This would work like this: switch( a, { "foo", "bar", "grill" } ) -- David Cuny
18. Re: goto's, and loops
- Posted by Jason Gade <jgade at PCEZ.COM> Jul 31, 1999
- 546 views
Hi, Bernie. All I got from your message was a quote of the C code. Were you going to add something? -----Original Message----- From: Bernie Ryan +ADw-bwryan+AEA-PCOM.NET+AD4- To: EUPHORIA+AEA-LISTSERV.MUOHIO.EDU +ADw-EUPHORIA+AEA-LISTSERV.MUOHIO.EDU+AD4- Date: Thursday, July 29, 1999 10:28 PM Subject: Re: goto's, and loops +AD4-On Thu, 29 Jul 1999 21:35:24 -0700, Jason Gade +ADw-jgade+AEA-PCEZ.COM+AD4- wrote: +AD4- +AD4APg-Although I haven't worked on the program for awhile, I wondered about +AD4-goto's +AD4APg-when trying to port the Rogue role-playing game from C to Euphoria as an +AD4APg-exercise. Here is the original code: +AD4APg- +AD4APg-main(argc, argv) +AD4APg-int argc+ADs- +AD4APg-char +ACo-argv+AFsAXQA7- +AD4APgB7- +AD4APg- /+ACo- Save the setuid we have got, then turn back into the player +ACo-/ +AD4APg- saved+AF8-uid+AD0-geteuid()+ADs- +AD4APg- setuid(true+AF8-uid+AD0-getuid())+ADs- +AD4APg- +AD4APg- if (init(argc, argv)) +AHs- /+ACo- restored game +ACo-/ +AD4- +AD4- SET NEW GAME FLAG +AD4- goto PL+ADs- +AD4APg- +AH0- +AD4APg- +AD4APg- for (+ADsAOw-) +AHs- +AD4- +AD4- IF ( NEW GAME ) +AHs- +AD4- +AD4APg- clear+AF8-level()+ADs- +AD4APg- make+AF8-level()+ADs- +AD4APg- put+AF8-objects()+ADs- +AD4APg- put+AF8-stairs()+ADs- +AD4APg- add+AF8-traps()+ADs- +AD4APg- put+AF8-mons()+ADs- +AD4APg- put+AF8-player(party+AF8-room)+ADs- +AD4APg- print+AF8-stats(STAT+AF8-ALL)+ADs- +AD4- +AD4- +AH0- +AD4- +AD4-PL: +AD4APg- play+AF8-level()+ADs- +AD4APg- free+AF8-stuff(+ACY-level+AF8-objects)+ADs- +AD4APg- free+AF8-stuff(+ACY-level+AF8-monsters)+ADs- +AD4APg- +AH0- +AD4APgB9- +AD4- +AD4- +AD4-Bernie +AD4-
19. Re: goto's, and loops
- Posted by Bernie Ryan <bwryan at PCOM.NET> Jul 31, 1999
- 561 views
If you look at the codeI sent you, you will see that I inserted something into your code to show you that just adding an if statement would eliminate the goto statement. Bernie
20. Re: goto's, and loops
- Posted by Jason Gade <jgade at PCEZ.COM> Jul 31, 1999
- 556 views
Sorry, Bernie, but I lost the message because of hw problems. Can you resend it?? -----Original Message----- From: Bernie Ryan +ADw-bwryan+AEA-PCOM.NET+AD4- To: EUPHORIA+AEA-LISTSERV.MUOHIO.EDU +ADw-EUPHORIA+AEA-LISTSERV.MUOHIO.EDU+AD4- Date: Saturday, July 31, 1999 3:56 PM Subject: Re: goto's, and loops +AD4-If you look at the codeI sent you, you will see that I inserted something +AD4-into your code to show you that just adding an if statement would eliminate +AD4-the goto statement. +AD4-Bernie +AD4-
21. Re: goto's, and loops
- Posted by Bernie Ryan <bwryan at PCOM.NET> Jul 31, 1999
- 551 views
- Last edited Aug 01, 1999
On Sat, 31 Jul 1999 16:34:28 -0700, Jason Gade <jgade at PCEZ.COM> wrote: >Sorry, Bernie, but I lost the message because of hw problems. Can you >resend it?? >-----Original Message----- > >main(argc, argv) >int argc; >char *argv[]; >{ > /* Save the setuid we have got, then turn back into the player */ > saved_uid=geteuid(); > setuid(true_uid=getuid()); > > if (init(argc, argv)) { /* restored game */ SET NEW GAME FLAG > goto PL; > } > > for (;;) { IF ( NEW GAME ) { > clear_level(); > make_level(); > put_objects(); > put_stairs(); > add_traps(); > put_mons(); > put_player(party_room); > print_stats(STAT_ALL); } >PL: > play_level(); > free_stuff(&level_objects); > free_stuff(&level_monsters); > } >} Bernie
22. Re: goto's, and loops
- Posted by Jason Gade <jgade at PCEZ.COM> Jul 31, 1999
- 540 views
Thanx, Bernie. If I get back on that job I will see if that makes it more clear.
23. Re: goto's, and loops
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Aug 02, 1999
- 554 views
- Last edited Aug 03, 1999
Hello, Kat wrote: >Ok, what >about "repeat-until" loops? I didn't see them in Euphoria either. It's a >"while-do" loop with the test at the end instead of the beginning. Here is Euphoria's repeat-until loop while not <expression> do end while Isn't it nice that a single construct can be used for more than 1 job. I always thought that BASIC's do_until loop was redundant. later, Lewis Townsend _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com
24. Re: goto's, and loops
- Posted by John Kinsey <jkinsey at BELLSOUTH.NET> Aug 08, 1999
- 554 views
Hi all, If I remember right the only place to use a goto would be in an error trapping routine where you would not want the routine to return back to the next line after the error but instead break out and give an user error then quit. Other than that I cannot think of any structured modern day programming language that promotes the use of goto's. I would say that its better programming practice to stay away from the goto keyword for both the programmer writing the program and for others that are trying to figure out what that programmer did. As far as the loops go the only difference between a while-do and repeat-until is one is pessimistic and the other is optimistic. I don't really think that this would matter one way or the other, I guess it depends on how you think. That's my 2 cents Thanks, JKinsey -----Original Message----- From: Euphoria Programming for MS-DOS [mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Lewis Townsend Sent: Monday, August 02, 1999 4:19 PM To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: Re: goto's, and loops Hello, Kat wrote: >Ok, what >about "repeat-until" loops? I didn't see them in Euphoria either. It's a >"while-do" loop with the test at the end instead of the beginning. Here is Euphoria's repeat-until loop while not <expression> do end while Isn't it nice that a single construct can be used for more than 1 job. I always thought that BASIC's do_until loop was redundant. later, Lewis Townsend _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com
25. Re: goto's, and loops
- Posted by Bernie Ryan <bwryan at PCOM.NET> Aug 08, 1999
- 538 views
>> If I remember right the only place to use a goto would be in an error >>trapping routine where you would not want the routine to return back to >>the next line after the error but instead break out and give an user >>error then quit. Other than that I cannot think of any structured modern >>day You don't need a goto for the above just print the error and use the Euphoria abort. Bernie
26. Re: goto's, and loops
- Posted by John Kinsey <jkinsey at BELLSOUTH.NET> Aug 09, 1999
- 618 views
- Last edited Aug 10, 1999
Right I understand that this is true but that would mean that you would be doing what is known as inline error checking in large programs you might want to deploy an error handler which is centrally located and handles multiple errors. When I made the statement is was not directed to any one programming language it is a general observation of several programming languages. Besides lets say that the error is not fatal and it is possible for your application to continue by giving your user another option to use. While yes you can use what you suggested and close the program but in an event driven application you don't always know what the user is going to do or what others programs are going to effect yours like MS *.dll's, not only that but you don't want to duplicate code so send it to a central location and handle the error. So you must trap for all of these errors and if they are fatal then yes have your program gracefully bow out with an error message and abort but if not then let some error handler routines try to work around the error or continue with the error by the above mentioned way. That's where it might be prudent for the programmer to use a goto to bypass code that your program knows will fail and use a different procedure to perform the same method or prompt the user and ask what to do next for example lets say that you are writing a routine for the user to open a file and your program cannot find the file then you would send it to the error handler with and error code and prompt the user for the file that is missing then bypass the previous statement with a goto and continue to the next procedure. Most languages that are very event driven (ie..VB,Delphi, most visual programming languages for GUI's) use these methods so that even with an error the program can still successfully accomplish the job. If there is any other questions about gotos you can reach me off the list at jkinsey at bellsouth.net Here is the deal. A) don't assume that I know what I am talking about. B) don't assume anything at all. C) There is a reason why the developer of the language put every keyword in the language D) The easiest way only looks easy at first. E) If you use a goto then heavily document your code so that even your dog would understand what you are trying to accomplish and when you are finished documenting it you will probably find that you didn't need it and replace it with another structure anyway. F) Keep an open mind the worst thing that you can do is go into a program that has been written with gotos and start deleting everyone that you find without reading the code. especially if you are not used to reading gotos and really hate them. G) This comment is only here to finish the byte so that the last ones will look like a word. Thanks JKinsey -----Original Message----- From: Euphoria Programming for MS-DOS [mailto:EUPHORIA at LISTSERV.MUOHIO.EDU]On Behalf Of Bernie Ryan Sent: Sunday, August 08, 1999 11:06 AM To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: Re: goto's, and loops >> If I remember right the only place to use a goto would be in an error >>trapping routine where you would not want the routine to return back to >>the next line after the error but instead break out and give an user >>error then quit. Other than that I cannot think of any structured modern >>day You don't need a goto for the above just print the error and use the Euphoria abort. Bernie