Rich Mellor wrote, on 03/11/2010 17:49:
On 02/11/2010 17:34, Tony Firshman wrote:
10 FOR j = 1 TO 100
15 sp$ = " ";
20 PRINT j;
20 if  j/3 == int(j/3)
25 sp$="";
30 PRINT " FIZZ";
40 END IF
30 IF j/5 == int(j/5)
40 PRINT sp$&"BUZZ";
50 END IF
60 PRINT
70 END FOR

Hi Tony,

Yes, you are going to confuse SB programmers with that one - corrected version and (improved) is:

10 FOR j = 1 TO 100
15   sp$ = " "
20   PRINT j;
20   IF  j/3 = int(j/3) : sp$="": PRINT " FIZZ";
30   IF j/5 = int(j/5): PRINT sp$&"BUZZ";
40 PRINT
50 END FOR j

You can also use
20   IF j MOD 3=0 : sp$="": PRINT " FIZZ";
30   IF j MOD 5=0: PRINT sp$&"BUZZ";

He he - I also had to remove brackets in the IF clause.
I always forget the perl equiv operator as well as it changed from earlier versions.
The core logic though was fine - phew.
... but there are also two line 20s!

Tony


--
QBBS (QL fido BBS 2:257/67) +44(0)1442-828255
[email protected] http://firshman.co.uk Voice: +44(0)1442-828254 Fax: +44(0)1442-828255 Skype: tonyfirshman
   TF Services, 29 Longfield Road, TRING, Herts, HP23 4DG

_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to