Re: break statement

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

From: andrea catto' (acatto_at_dataflight.com)
Date: 05/06/04


Date: Thu, 6 May 2004 10:44:38 -0700

AHHHHHHHHHHHHHH
NO GOTO PLEASE !!!!!!!!

It is possible............ EVERY GOOD PROGRAMMED WOULD NEVER USE GOTOS....

I used gotos in gwbasic in the msdos days, !!!!!!!! aweful, I used
gotos/jmps in assembly back then.......
in assembly only they are necessary.......

in C they are provided and yet they make the code flow hard to deal with and
dont achieve things any better then using while/loops/fors....

just refer to what Gabriele G. Ponti first wrote, use beark; to get off the
inner loop and a flag to get off the outer one or yet anothe break.

"Mark Broadbent" <no-spam-please@no-spam-please.com> wrote in message
news:OckOl54MEHA.2540@TK2MSFTNGP10.phx.gbl...
> 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: goto
    ... nor just in your opinion. ... int getStdI ... use a GOTO since 1983. ... "That excessive bail ought not to be required, nor excessive fines imposed, ...
    (comp.lang.c)
  • Re: Breaking out of nested subroutine?
    ... there will be no need for goto statements. ... I've no doubt that Mr. Dijkstra would have the same dim opinion about ... Perl as a language as he had for 'goto' as a statement. ...
    (comp.lang.perl.misc)
  • Re: NO STARHOPPING ALLOWED!!!
    ... why is having a difference in opinion such a big ... learn the sky first." ... whether they can learn it better in time, having first used GOTO. ... has established any kind of iron-clad case. ...
    (sci.astro.amateur)
  • Re: The use of goto in C
    ... >> In another forum I am involved in a discussion regarding the use of goto. ... > That opinion is stupid. ... The cost is your life. ...
    (comp.lang.c)