Path: number1.nntp.dca.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.zanker.org!zen.net.uk!dedekind.zen.co.uk!newsfeed.esat.net!news2.telebyte.nl!news.icp.pl!newsfeed.atman.pl!news.intercom.pl!f124.n480!f127.n480!f112.n480!f200.n2432!f605.n774!f500.n123!f514.n250!not-for-mail
Newsgroups: fido.science
Distribution: fido
From: DAVID WILLIAMS
Date: Fri, 13 Aug 04 08:13:42 +0200
Subject: Pythagorean triples
Message-ID:
Organization: The Bayman BBS,Toronto, (416)698-6573 - 1:250/514
111
300
Lines: 60
Xref: number1.nntp.dca.giganews.com fido.science:310
-> DW> -> SUB Delay (t%)
-> DW> -> StopTime& = TIMER + t%
-> DW> -> DO
-> DW> -> IF LEN(INKEY$) THEN EXIT DO
-> DW> -> LOOP UNTIL (StopTime& - TIMER) MOD 86400 <= 0
-> DW> -> END SUB
-> DW> I usually use rather simpler code:
-> good! because that code fails at midnight.
Maybe. I'm not sure. I never use MOD with negative numbers. The way
BASIC does it doesn't make sense to me. I figure that -5 MOD 3 should
come to 1, since the next-lower multiple of 3 is -6, and -5 is 1 more
than that. But BASIC says it's -2, or something. I think it's related
to FIX, which I also almost never use.
It makes good sense to me to write:
SUB Delay(D!)
T! = TIMER
DO
IF TIMER < T! THEN T! = T! - 86400
IF LEN(INKEY$) THEN EXIT DO
LOOP UNTIL TIMER >= T! + D!
END SUB
At midnight, TIMER jumps backward by 86400 seconds, so this code just
makes T! jump back by the same amount, so they keep the same
relationship to each other. Of course, this makes T! have a negative
value, but that doesn't matter.
-> I do it this way to avoid arithmetic and the need to consider roll-over at
-> midnight.
-> sub delay (s)
-> for x=1 to s*18.6
-> t=timer
-> while t=timer
-> if inkey$ "" goto done
-> wend
-> next
-> done:
-> end sub
-> Jasen
Isn't "s*18.6" arithmetic?
More seriously - in some BASICs - you make it jump out of the loop if a
key is pressed, without cleaning the FOR... information off the stack.
Some BASICs will sort this out for you, but others won't, and will lead
you into all kinds of tangles later. It would be better to use EXIT FOR
than the GOTO.
My $0.02 worth.
dow
|