Loop with a known number of repetitions "repeat N:
"
If you need to execute some sequence of the same commands
N
times in the program, then to shorten the code, use the construction:
repeat N:
commands
For example, program:
forward
forward
forward
forward
you can write shorter:
repeat 4:
forward
Such a construction is called a
loop with a known number of repetitions. The use of loops in the program significantly reduces the size of the program, and hence the memory occupied by the program.
Loops is a key concept in computer science. If you want to be a good programmer, knowing how to handle loops is the most important skill to learn.
In order to show the robot which commands to repeat,
indent 4 spaces from the beginning of the line!
Indentation is very important in Python. By indenting, we define a certain block of commands that must be executed in a loop, or after checking the condition.