Re: Using Wildcards in a Select Case Statement ?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Duane Bozarth (dp_bozarth_at_swko.dot.net)
Date: 07/15/04


Date: Thu, 15 Jul 2004 13:47:25 -0500

Bob O`Bob wrote:
>
> Gale Green wrote:
>
> > I *never* alter the value of the control variable of a For loop (and I
> > never rely on its contents after the loop either). If the variable
> > needs manual intervention during processing, for whatever reason, I
> > use Do...Loop, because the While/Until <condition> tells you that the
> > variable is changed inside the loop. There is also sometimes the
> > advantage that, after a Do...Loop, you *can* rely on the remanent
> > value of the control variable.
>
> I do it frequently
> (alter the For loop variable, and/or rely on its value after loop exit)
> It's always been safe, predictable, and 100% reliable for me.

That, of course, is dependent on the language specification (and then
the quality of the implementation for those that have formal Standards),
but at least for those with formal Standards it is known what the proper
behavior is supposed to be. I've never seen it documented conclusively
for VB and again a quick search didn't turn up any mention of a defined
behavior on exit. It's a case of "it may work, but there's no guarantee
it will always be that way". Since it's unlikely the compiler will now
change, it's not quite as much an issue. To me, the disconcerting thing
is that there's no indication the compiler <has> to do it the same for
all instances, so it is possible (albeit, unlikely, I tend to agree)
that behavior might depend on other things such as what code is in a
For...Next loop, for example. That's the worst possible scenario. But,
since it isn't defined, I don't rely on the behavior--if I would want
the loop index after a loop, I'd save a temporary just to make sure...

I note there is a recommendation <against> changing the loop variable
value in a For loop, but only as an admonition as to making for
occasional hard to debug behavior, not as illegal.



Relevant Pages

  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... >> both less efficient and less safe than the Fortran and Basic standard. ... >> The C for loop is actually trying to do what a do loop does. ... sloppy thinking that results from confusing a programming language ... > I do not believe that you are capable of writing a conforming C compiler. ...
    (comp.programming)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... it's a for loop in the C sense. ... > sloppy thinking that results from confusing a programming language ... >> I do not believe that you are capable of writing a conforming C compiler. ... Does Microsoft's C compiler perform this optimisation? ...
    (comp.programming)
  • Re: Histogram of character frequencies
    ... generated object code may simply be a loop in which elements are ... believe any C compiler anywhere would reject it. ... On the first iteration of the loop you test the end of file indicator ...
    (comp.lang.c)
  • Re: Fridays the thirteenth. (And a little puzzle.)
    ... -- compiler) is the usual method ... int febdays ... -- We're going to go round a loop dealing with each year in turn. ... -- other languages call) ...
    (uk.people.silversurfers)
  • Re: Interesting article by Randall Hyde
    ... >>> a test before executing the loop. ... is a compiler writer forced to ... And another thing you might consider is that compiler optimization was ... Then the programmer will have to protect the execution of that loop. ...
    (comp.lang.asm.x86)