Re: Looking for a way to convert dec to bin
- From: "Michael C" <nospam@xxxxxxxxxx>
- Date: Fri, 9 Mar 2007 19:20:02 +1100
"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:e$4EzWeYHHA.984@xxxxxxxxxxxxxxxxxxxxxxx
This method pre-supposes that x will be equal to count + 1 at the end of
the
loop, which is implied, but not specifically stated in the documentation,
though it dates back to MS BASIC. It's also language-specific; I believe
the value is undefined after looping in some languages.
It's set in stone now for vb but yes, many languages won't work. In well
designed languages the loop var is out of scope anyway.
Also, suppose <count> happens to be exactly the same as the maximum size
of x's data type. I *believe* (but haven't checked) that the for loop
will simply wrap around without checking (maybe, maybe not...certainly
would if overflow checking is turned off). In that case, "if x <= count"
will succeed where it shouldn't.
It will give an error, not wrap around. When using a byte, for x = 0 to 255
fails. For other languages I believe you'd have problems anyway, eg
for(byte b = 0; b <= 255; b++)
{
}
This loop will probably never exit because b is always 255 or less. So
writing a for loop that goes to the limit of a variable is not possible
anyway.
How so? I've searched collections many times without difficulty, so I'm
not sure what it is you're referring to. Do you mean a For Each...Next
loop?
Yep.
If so, I only ever use those where I KNOW I'm going to be iterating
through the entire collection. I don't like them in general for searching
because how do you find out the result after your Exit For?
Generally if I need the index then I won't use foreach. It's possible
(although highly unlikely) that foreach won't return items in index order so
incrementing your own index var is flawed, in theory at least. Foreach
should only be used if the index is not required and only the object is
required.
You have to have an extra variable to store the found result, and you have
no index into the collection once you're done (unless the collection
provides an index for you).
I don't think it makes much sense to avoid foreach just to avoid exit for.
Michael
.
- References:
- Looking for a way to convert dec to bin
- From: Kardon Coupé
- Re: Looking for a way to convert dec to bin
- From: Kardon Coupé
- Re: Looking for a way to convert dec to bin
- From: Michael C
- Re: Looking for a way to convert dec to bin
- From: Robert Morley
- Re: Looking for a way to convert dec to bin
- From: Jeff Johnson
- Re: Looking for a way to convert dec to bin
- From: Robert Morley
- Re: Looking for a way to convert dec to bin
- From: J French
- Re: Looking for a way to convert dec to bin
- From: Robert Morley
- Re: Looking for a way to convert dec to bin
- From: Michael C
- Re: Looking for a way to convert dec to bin
- From: Robert Morley
- Re: Looking for a way to convert dec to bin
- From: Michael C
- Re: Looking for a way to convert dec to bin
- From: Robert Morley
- Looking for a way to convert dec to bin
- Prev by Date: OT - Microsoft does listen...
- Next by Date: Re: Looking for a way to convert dec to bin
- Previous by thread: Re: Looking for a way to convert dec to bin
- Next by thread: Re: Looking for a way to convert dec to bin
- Index(es):
Relevant Pages
|