BBC BASIC for Windows
Programming >> BBC BASIC language >> REPEAT loops
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1389424629

REPEAT loops
Post by chrispc on Jan 11th, 2014, 06:17am

why doesn't the following give me 1,2...1,3...1,4 up to 1,9 and then 2,1...2,2...2,3 etc. up to 9,9 ? I must be a total idiot.
J%=0
K%=0

REPEAT J%=J%+1

REPEAT K%=K%+1

PRINT "(";J%;","K%;") = ";J%

UNTIL K%=9

UNTIL J%=9

END

THANKS FOR YOUR INDULGENCE.

Re: REPEAT loops
Post by admin on Jan 11th, 2014, 09:37am

on Jan 11th, 2014, 06:17am, chrispc wrote:
why doesn't the following give me 1,2...1,3...1,4 up to 1,9 and then 2,1...2,2...2,3 etc. up to 9,9 ?

Your initialisation of K% is in the wrong place. It should be after the first REPEAT:

Code:
      J%=0
      REPEAT J% += 1
        K%=0
        REPEAT K% += 1
          PRINT "(";J%;","K%;") = ";J%
        UNTIL K%=9
      UNTIL J%=9
      END 

Richard.