Message-ID: <005a01bffd43$030a3520$0500007b@brk> From: "Johan Henriksson" To: Subject: Re: BREAKing out of a nested loop Date: Thu, 3 Aug 2000 13:57:32 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Reply-To: djgpp AT delorie DOT com >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. >>Hullo. I would like a little help with something. I've written a simple >>collision-detection program, but I need a little clarification with >>something: >> >> >>for(int a = 1; a <= pptest_w; a++){ >> for(int b = 1; b <= pptest_h; b++){ >> pixelcheck = getpixel(pptest_1a, a, b); >> if(pixelcheck <= 0){ >> }else if(pixelcheck != 0){ >> pixelcheck = getpixel(pptest_2a, a, b); >> if(pixelcheck <= 0){ >> }else if(pixelcheck != 0){ >> collide = 1; >> break; >> } >> } >> } >>} >> >>FUNKtion(); >> >>I would like to get it to break as soon as a collision is detected and go >>straight to FUNKtion(). Is this enough to bust out of all those nested >>loops? Putting if(collide){break;} latter in that mess would be kind of >>stupid because you're just putting it in another loop, correct? Any help >>will be appreciated. Thank you.