JRS: In article <c9************ *******@news.de mon.co.uk>, seen in
news:comp.lang. javascript, Mark Anderson <ma**@notmeyear dley.demon.co.u k
posted at Fri, 28 May 2004 16:45:50 :
A 'for' loop takes 3 arguments (initialize; test; increment). The 'test'
must equate as true or false
ISTM that this is not a matter for the FAQ, but that it is a matter for
tutorials.
In different languages, loops are expressed in many different ways; but
ISTM that in the relevant respect there are exactly two different
classes.
For any loop, there is an initialisation, there is a change-between-
loops, and there is a condition. The condition is always equivalent to
a Boolean - that is inevitable, though Booleanisation may be implicit.
One class of loop has a termination condition; false to run.
One class of loop has a continuation condition; true to run.
The first class is exemplified by
Algol's for J := 3 step 6 until 9 // J=9
Pascal's for J := 8 down to 4 // J=4
repeat Inc(J) ; ... until J=9
(the first two could be interpreted with <=, and are probably
implemented that way; but the mind is likely to consider the condition
as "finish after J equals given value");
and the second by
Javascript's for (J=3 ; J<=9 ; J+=6)
Pascal's while J<9 do begin Inc(J) ; ... end ;
In the second, the Boolean is usually, but not always, an ordered
comparison - > >= < <=, explicit or implicit. However :
for (J=new Date();J.getMon th()==4;J=new Date()) {}
for (J=new Date();J.getMon th()!=5;J=new Date()) {}
should, ISTM, each loop until June.
The OP has been giving a termination condition where a continuation
condition is required.
There is another dichotomy, that of whether the finalisation condition
is evaluated before or after the loop body
while (new Date()<12345678 90000) {}
do {} while (new Date()<12345678 90000)
each of which should loop until 2009-02-13 Fri 23:31:30 GMT. IIRC, a
FORTRAN IV loop tested at the end, so the loop was always executed once;
but an Algol 60 loop tested at the beginning.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.