Re: Looking for a way to convert dec to bin



"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: 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: Cases where Forth seems a little clunky
    ... complexity of stack shuffling by the complexity of exotic operators. ... with Forth derived languages under RPN. ... that one (I'm lying a bit, I double checked the loop more thoroughly a ...
    (comp.lang.forth)
  • Re: Very poor Lisp performance
    ... Observe LOOP, ... than many Lisp users, as LOOP is offensive to a percentage of Lisp ... >>> natural and programming languages have complicated grammars precisely ... do you agree that languages are evolving to be more concise? ...
    (comp.lang.lisp)
  • Re: Cases where Forth seems a little clunky
    ... complexity of stack shuffling by the complexity of exotic operators. ... with Forth derived languages under RPN. ... that one (I'm lying a bit, I double checked the loop more thoroughly a ...
    (comp.lang.forth)

Quantcast