Re: break statement

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mark Broadbent (no-spam-please_at_no-spam-please.com)
Date: 05/06/04


Date: Thu, 6 May 2004 18:20:16 +0100

whilst I am no expert, let me make a few comments.
You could use the goto statement (with a label to jump to) however this is
usually necessary when the code is bad.

>From your code snippet it is very hard to see exactly what you are trying to
do but the chances are you could do a secondary && test within the while
loop -either moving the if statement test itself, or if that is not possible
setting a boolean flag
e.g.

bool loopFlag = true;
while (intCurCategory < intTotalCategories && loopFlag)
{
     for (intPageIter = 0;intPageIter< ITEMS_PER_PAGE;intPageIter++)
     {
          if (intPagesDisplayed>ITEMS_PER_PAGE)
                loopFlag = false;
                break; //this will break the for loop
          intPagesDisplayed++
      }
}

The other thing that strikes me about the code is the god awful naming of
the integers. Ive been banging on for a while in the CSharp newsgroup about
the lack of a firm standard when naming private variables , controls etc.
And I intend to put this right myself sometime because it's something that I
believe slows down development time cos you are constantly thinking "what
shall I call this". I think the general consensus is that for private
variables you should name them in Hungarian format (as you did) , but you
dont need the "int" in a type safe environment this is extreme overkill in
my opinion (plus is confusing to the eye when a variable declaration could
be "int variableName = value", also the names should be functionally
descriptive (as you did) rather than abbreviated rubbish.
For my form controls however I am currently of the opinion to prefix those
(a la VB format) since it makes my life easier finding them using
intellisense however I have had one expert tell me he doesnt do this either!

I hope some of this helps! Good luck.

-- 
Br,
Mark Broadbent
mcdba , mcse+i
=============
"Patrick" <patl@reply.newsgroup.msn.com> wrote in message
news:eFqU8i4MEHA.2976@TK2MSFTNGP10.phx.gbl...
> How could I break out of the while loop within the for/if loop below
>
> while (intCurCategory < intTotalCategories)
> {
>      for (intPageIter = 0;intPageIter< ITEMS_PER_PAGE;intPageIter++)
>      {
>           if (intPagesDisplayed>ITEMS_PER_PAGE)
>                   break;   //trying to break out of the while loop here!
>           intPagesDisplayed++
>       }
>
> }
>
>


Relevant Pages

  • Re: The void** pointer breaking symmetry?
    ... Is that maybe all an urban legend? ... hopes that future versions of the C standard will cut the crap and save ... outer loop, which will save another bunch of millions. ... an easy workaround: the goto statement. ...
    (comp.lang.c)
  • Re: acceptable use of goto?
    ... Ed Prochak wrote, On 20/03/08 17:17: ... than using the goto statement. ... Branching should only go ... Wait until you have worked on code that branches forward in to a loop, forward within the loop at various points, then forward out of the loop. ...
    (comp.lang.c)
  • Re: F90 coder needs help with F77-style control flow
    ... Can anyone help me understand what this goto statement is actually ... It gets out of the loop, and out of any loops inside the one displayed ... maxiter ... if exit bigloop ...
    (comp.lang.fortran)
  • Re: loops - Case where gotos cannot be removed (optimization)
    ... void myfuncA ... switch { ... Not even one goto statement. ... A loop construct to ...
    (comp.lang.c)