Idea 5of 23Builds onA variable holds one number
A loop repeats the lines inside it
How can code do the same step many times?
Today you'll discover
- what REPEAT does
- how to count the passes
- what END marks
Think firstSET 2, then REPEAT 4 TIMES: ADD 3
What does this program output?
Decide first, then press Next. Count the passes, and watch a bar appear for each one.
Code on the left: SET 2, REPEAT 4 TIMES, ADD 3 inside it, END, OUTPUT, with a pass counter under it. On the right, bars drawn from 0: start 2, then 5, 8, 11 and 14 after passes 1 to 4, each marked plus 3. The last bar, 14, is ringed. The last step asks about SET 30 and three passes of SUBTRACT 4.
See the whole ideathe big idea and the key word, in one place
The big idea
A loop repeats the lines inside it, once on every pass, then the code goes on.
Pass by pass
Start at 2 and add 3 on each of 4 passes: 5, 8, 11, 14.
- start2
- pass 15
- pass 28
- pass 414
Easy to get wrongOnly the lines between REPEAT and END repeat. A line after END runs once, after the last pass.
Key word
- loop
- code that repeats the lines inside it a set number of times, like REPEAT 4 TIMES
Ready to use it?
- Say what a loop outputs after a number of passes.