Re: how do people feel about exit function from loop



I think it all comes back to the reason we allow more than 2 or 3 characters
for a variable name in the first place. For myself, as a general rule, if I
have nested loops, I try to make the index names indicate their function.
For example:

For lngRow = 1 To 10
For lngCol = 1 To 10
SomeArray(lngRow, lngCol) = SomeArray(lngRow, lngCol) + 1
Next
Next

That said, in something not nested, I'll often use a simpler name (unless
I'm already using a logical name in other loops), even though when you think
about it, the context is nearly the same. For example:

For i = 1 To 10
SomeArray(1, i) = SomeArray(1, i) + 1
Next

But at the risk of inciting another debate over what constitutes style, I
believe this is a style choice for each user to decide on their own.



Rob

"dpb" <none@xxxxxxx> wrote in message news:f8l833$6qj$1@xxxxxxxxxxx
Ralph wrote:
"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message
news:OArXqJs0HHA.3916@xxxxxxxxxxxxxxxxxxxxxxx
"Steve Gerrard" <mynamehere@xxxxxxxxxxx> wrote

* Does the loop index have a meaningful name?
Does "n" count as a meaningful name? :)

I use single letter variables almost exclusively as for loop indexes
used with
arrays, so to me it is.

You must be one of those GenX coders, eh? <g> I come from an era when
3 was the magic number for characters in a variable name. idx (index),
itm (item), row & col, etc... About the only time I'd use a single
letter for
an iterator would be for referencing X and Y coordinates and the
occasional
throw-away test routines.


I use idx 'n such, mainly because it always seemed more readable and more
amendable for search 'n replace. But then I occasionally side to the dark
side and use i% and n&. <g>

Almost nothing I hate more than something like

my_wonderfully_named_array(uselessly_described_index) = _
my_wonderfully_named_array(uselessly_described_index) + _
your_wonderfully_named_array(uselessly_described_index-1)+1

:(

Unless there's a really solid reason for otherwise in a specific
application, indices of For...Next loops _should_ be brief and the
traditional i,j,k,..., etc. Offhand, I have a hard time of thinking of a
place that does justify the use of the longer name that tends to obfuscate
more than clarify.

If there's any doubt at all of the intent or the reason for the iterator
being the values it takes on, a comment adds that explicitly and doesn't
distract further from the code itself.

In VB for deep or long loops I either make sure to declare them as Long or
do use the "&" for the performance gain of the Long over the Integer.

imo, ymmv, $0.02, etc., ...

--


.



Relevant Pages

  • Re: POS Printer
    ... printer These special codes are non-printable ... characters ... I see no reason to be concerned with it at all. ... I know that a POS printer has an internal buffer so just because we send ...
    (microsoft.public.vc.mfc)
  • Re: What is the maximal length of usernames on Solaris?
    ... You've just made the determination that eight characters is it ... >> that this is a reason not to try and change it. ... >> I don't know how many times I've been preaching the merits of UNIX to ... >for updating all the apps and spending it on his bonus. ...
    (comp.sys.sun.admin)
  • Re: Y&R Tuesdays Show
    ... for not a very good reason except corporate mandate. ... I find Victor compelling when he's in cold/angry mode...but I ... Many actors/actresses have said that they'd much rather play evil than ... long-tenured characters that don't learn from their mistakes. ...
    (rec.arts.tv.soaps.cbs)
  • Re: Layering: For a moment, she stood in silence
    ... then pull back to the present time scene. ... reason to talk about it, and you have to get that across _before_ ... just that with this rambling, there's nothing new for the characters. ...
    (rec.arts.sf.composition)
  • Re: Wolf In The Fold - Plot, New Effect
    ... [For some reason I got this post with absurdly long lines, ... I'll have a fair number of points with the joke based on the Federation treating Argelius ... if the point needed to be made with our characters rather than ...
    (rec.arts.startrek.tech)