Mark Broadbent said:
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
I wouldn't suggest talking consensus on this issue. Its actually probably
pretty split. I for one hate hungarian and I'm not alone. Its a bad standard
and, IMHO, it turns good code into nearly unreadable rubbish. Well named
variables will pretty much always remove the need for any prefixes, be they
scope or type. We have probably argued the issue before, I've been involved
in a couple of the naming convention debates, but I still think its
irresponsible to decide what the consensus is off the cuff. Let the OP look
around and find all of debate on the issue, if he cares to do so, and let
him draw his own conclusions. Beyond that, let him write his code as he
wishes, he may think your variable naming is godawful as well.
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 still prefer well named variables, although I do do this oftentimes with
textboxes. I prefer
customerNameTextBox to txtCustomerName, however they both have a major
flaw...they convey incorrect information if the text box is changed to a
combo box. In some cases it isn't a big deal, but the hungarian notation
bites you if you don't change it. txtCustomerName better be a text box, not
a combo box or your variable name is wrong. It gets trickier when you throw
in 3rd party controls...treeCustomers may be a standard TreeView, or it may
be DevExpresses TreeList, or it may be something else entirely. The name
treeCustomers implies TreeView, but often enough its wrong. This shows a
major problem with hungarian, sometimes the variable names imply both a type
and a use and cross eachother up doing it. I've been trying to find a
better naming scheme for this that increases freedom and reduces the
confusion, but I havn't so far. You always seem to add the name of the base
control type to the variable. Hopefully refactoring will solve what naming
conventions can't seem to, in this case.