Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

74 14 REPEAT...UNTIL, TRUE, FALSE Computers are fundamentally pretty stupid things but their power comes from their ability to repeat things many times – sometimes many millions of times in one second. In this version of BASIC two types of repeating loops can be used. They are called REPEAT...UNTIL and FOR...NEXT loops. This chapter explains REPEAT...UNTIL loops and the next deals with FOR...NEXT loops. Do you remember the story about a man starting with one grain of rice and doubling it each time he won a bet? How many times would he have to double his grains of rice to own more than a million grains?

In the following program C is a counter showing how many times the number of grains has doubled and X represents the number of grains of rice. 10 X=1 20 C=0 30 REPEAT 40 X=X*2 50 C=C+1 60 UNTIL X>1000000 70 PRINT C,X >RUN 20 1048576 Lines 30 to 60 are called a REPEAT...UNTIL loop and everything within the loop is repeated until X is greater than one million. The ‘terminating condition’ in this program is that X is greater than 1000000. The next program terminates after 15 seconds. Line 40 reads the starting time and the program repeats until the present time minus the starting time is greater than 1500 hundredths of a second – the internal clock ticks a hundred times a second.

10 PRINT "SEE HOW MANY SUMS YOU" 20 PRINT "CAN DO IN 15 SECONDS" 30 PRINT 40 STARTTIME=TIME 50 REPEAT 60 F=RND(12)