Re: Looking for a way to convert dec to bin

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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


.



Relevant Pages

  • Re: how do people feel about exit function from loop
    ... stand out to me far better than a For Next loop for that, ... line, the line that starts the loop, I know ALL the exit conditions for the ... And now we get back to why Goto is "silly" when Exit is not. ... as I have knowledge of only a few languages. ...
    (microsoft.public.vb.general.discussion)
  • Re: How to copy multi object array contents into single object arrays?
    ... languages most recognizable for blocks delimited with curly braces. ... hoisting the loop bound.) ... As to the efficiency claims, ... I see differences in integer array look-ups, ...
    (comp.lang.javascript)
  • Re: PCL trash
    ... whether there are some social reasons, ... the equivalents of LOOP? ... dialect of CL, and not directed toward other languages, or other ... How is Scheme a close dialect of CL? ...
    (comp.lang.lisp)
  • Re: Checking a list for a value
    ... I am going to guess that the foreach is not the right way to address this problem. ... Your logic says to exit the loop on the first array element that DOES NOT ...
    (perl.beginners)
  • Re: PCL trash
    ... I very explicitly defined the concept of "LOOP." ... but it looks like Common Lisp can do everything Scheme ... languages is disingenuous and perhaps purposely misleading. ... Dialects of programming languages? ...
    (comp.lang.lisp)