Re: how do people feel about exit function from loop
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jul 2007 14:08:35 -0400
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> wroteused with
* 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
letter forarrays, 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
an iterator would be for referencing X and Y coordinates and theoccasional
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., ...
--
.
- Follow-Ups:
- References:
- how do people feel about exit function from loop
- From: greg
- Re: how do people feel about exit function from loop
- From: Ken Halter
- Re: how do people feel about exit function from loop
- From: Jan Hyde (VB MVP)
- Re: how do people feel about exit function from loop
- From: Steve Gerrard
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: Steve Gerrard
- Re: how do people feel about exit function from loop
- From: Larry Serflaten
- Re: how do people feel about exit function from loop
- From: Ralph
- Re: how do people feel about exit function from loop
- From: dpb
- how do people feel about exit function from loop
- Prev by Date: Re: Deployment under Vista
- Next by Date: OT: Re: Wii bit of help please???
- Previous by thread: Re: how do people feel about exit function from loop
- Next by thread: Re: how do people feel about exit function from loop
- Index(es):
Relevant Pages
|