|
[Date Index]
[Thread Index]
[Author Index]
Fwd: Re:Until -Reply -Reply
- To: mathgroup at smc.vnet.net
- Subject: [mg7263] Fwd: [mg7235] Re:[mg7063] Until -Reply -Reply
- From: BobHanlon at aol.com
- Date: Tue, 20 May 1997 02:59:06 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
The While[body; test] needs a semi-colon rather than a comma:
n=10; While[(n=n-1)>5, Print[n]]
9
8
7
6
n=10; While[Print[n]; (n=n-1)>5] (* note semi-colon *)
10
9
8
7
6
Bob Hanlon
---------------------
Forwarded message:
From: sean at mail.creol.ucf.edu (Sean Ross)
To: mathgroup at smc.vnet.net
To: mathgroup at smc.vnet.net
Sean:
>The forms:
>.....; or yours
> Until[test_,body_]:=While[test=!=True,body];
>work fine, but are not a true Until because they don't execute body first.
Mine is
SetAttributes[Until,HoldAll]
Until[test_, body_]:= While[body;test=!=True]
and does execute body first:
i=1;Until[True,i++];i
2
Am I missing something?
Allan Hayes
Thanks for the help. Your code does work and yes, you are missing
something. As an "insider", you were aware of an undocumented While
feature when I assumed that your While[body,test] was just a typo that I
saw no need to quibble about. The mathematica book does not mention
that While[test,body] evaluates test first, then body and While[body,test]
does the reverse. I will promptly "Update" my personal copy of the
mathematica book. This would probably make a nice addition to the list of
revisions you are compiling somewhere.
Prev by Date:
simple PDF
Next by Date:
How to write efficiently a large matrix of real numbers to an ASCII file
Previous by thread:
Re: Re: Until -Reply -Reply
Next by thread:
"lowess" regression
|