From: eglebbk AT dds DOT nl (Evert Glebbeek) Newsgroups: comp.os.msdos.djgpp Subject: Re: BREAKing out of a nested loop Date: Thu, 03 Aug 2000 22:48:46 GMT Organization: Physics student, University of Amsterdam Lines: 54 Distribution: world Message-ID: <3989f2c4.3822910@news.wins.uva.nl> References: <005a01bffd43$030a3520$0500007b AT brk> <3989d7e4_1 AT news DOT uni-bielefeld DOT de> NNTP-Posting-Host: stol-117-209.uva.studentennet.nl X-Trace: info.wins.uva.nl 965342800 1901 145.98.117.209 (3 Aug 2000 22:46:40 GMT) X-Complaints-To: usenet AT science DOT uva DOT nl NNTP-Posting-Date: Thu, 3 Aug 2000 22:46:40 +0000 (UTC) X-Newsreader: Forte Free Agent 1.11/32.235 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Newsgroup: comp.os.msdos.djgpp From: manni DOT heumann AT gmx DOT de (Manni Heumann) On Thu, 03 Aug 2000 20:36:39 GMT >djgpp AT delorie DOT com wrote: >>>Try 'goto'. You'll love it. They never taught you about it in >>>school. >> >>EEK! There are reasons for this! GoTo is "forbidden"! Nicer is to put this >>into a function >>that returns TRUE/FALSE. So, as soon as a collition is detected, you jump >>out of the >>function with false. This will break the loops. Might be considered cheating >>but it >>helps for making the code more usable so there is a good fix to this >>problem. >> > >Name just one of those reasons agains goto, other then "it looks like >BASIC and real hardcore C coders don't use that kiddy stuff."! If you give in to the temptation of using goto, you might consider using it more often. Too many goto's will make your code completely unreadable (yup, I started in BASIC too). >I didn't yet see one solution in this thread, that was as easy to read >as a simple little goto. Not exactly true, IMO. > Checking a flag for every for, Granted. >building the whole nest in a function and return? No, this is the way to do it. I always split my code in small functions that perform logical tasks, collision detection would be one of these. >Picture yourself reading that code! Doing it all the time. Actually, I find something like if (sprites_collide(sprite1, sprite2)) do_mega_big_explosion(); very readable. >Goto will also give you the benefit of feeling superior to the >moron who still uses goto after all this years:-) Sorry, you've lost me. >Back to the beginning: Name one reason against using goto. At least >name the law the forbids using goto. Using goto often will result in code that is harder to read. Cases where goto is needed can usually be worked around using functions (as in this example). >Come on, convince me! Well, all I can do is explain why I don't use goto. If you really feel you *have* to use goto, sure, go ahead. Regards, Evert Glebbeek