Re: Odd VFP DO WHILE Behavior
- From: "Roger Ansell" <notmyreal@xxxxxxxxxxxxxxxx>
- Date: Tue, 24 Apr 2007 20:25:39 +0930
"Jack Jackson" <jacknospam@xxxxxxxxxxxxxxx> wrote in message
news:37gq239291g6la6dmh3jpdjtu6ub75cm34@xxxxxxx
I noticed the following odd behavior (in VFP9).
LOCAL xx
xx = .NULL.
DO WHILE xx
...
ENDDO
The loop code is not executed, which is what I would expect.
LOCAL xx
xx = .T.
DO WHILE xx
xx = .NULL.
ENDDO
The loop code is executed forever. Doesn't that seem wrong?
At first sight, it does appear odd but if you think about
it, both of your examples demonstrate a similar effect.
In the first, xx is null and Do While must evaluate to .T.
(or more precisely, must not evaluate to .F.) to execute the
code in the loop - so the loop code isn't executed.
As you say, that's what you'd expect.
In the second example, xx starts off as .T. and the code
in the loop is executed ... as expected. But in the loop,
you change the value of xx to null, so the Do while .T.
statement evaluates to null, not .F., so it's ignored
and your loop continues - just as if you type the
following in the command window:
z = Null
?z = .T. && returns .NULL. not .F.
So, to be safe, in your second example, you should ...
Do While xx Or ! Isnull(xx)
...
EndDo
HTH
-Roger
.
- References:
- Odd VFP DO WHILE Behavior
- From: Jack Jackson
- Odd VFP DO WHILE Behavior
- Prev by Date: Odd VFP DO WHILE Behavior
- Next by Date: Re: Odd VFP DO WHILE Behavior
- Previous by thread: Odd VFP DO WHILE Behavior
- Next by thread: Re: Odd VFP DO WHILE Behavior
- Index(es):
Relevant Pages
|
Loading