Re: break statement
From: Mark Broadbent (no-spam-please_at_no-spam-please.com)
Date: 05/06/04
- Next message: Tian Min Huang: "RE: Rolling my own Install w/ MSDE"
- Previous message: andrea catto': "Re: break statement"
- In reply to: Patrick: "break statement"
- Next in thread: andrea catto': "Re: break statement"
- Reply: andrea catto': "Re: break statement"
- Reply: Daniel O'Connell [C# MVP]: "Re: break statement"
- Messages sorted by: [ date ] [ thread ]
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++
> }
>
> }
>
>
- Next message: Tian Min Huang: "RE: Rolling my own Install w/ MSDE"
- Previous message: andrea catto': "Re: break statement"
- In reply to: Patrick: "break statement"
- Next in thread: andrea catto': "Re: break statement"
- Reply: andrea catto': "Re: break statement"
- Reply: Daniel O'Connell [C# MVP]: "Re: break statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|