Control: loops
Practical case:
To better understand what repetitions are, make a program that draws two dashed lines.
Solution:
You can duplicate the blocks (right click - duplicate) so you don't have to build the same thing twice.
What if you had to paint many lines? That is, repeat the same thing many times. Then you can add a control block to do repetitions. Repetitions are also called "loops." It is possible to add 3 types of loops:
- They repeat themselves constantly, forever.
- They are repeated a specific number of times
- They repeat until a condition is met
Practical case
Create a program that draws 10 dashed lines in a row.
Solution
Practical case
Create a program that draws a square.
Solution
There are two possible solutions to drawing the square using the block of repetitions. Below are the two possible programs.. The pencil up and down blocks can be inside or outside the repetition block. In this example the result will be the same, although the one on the left is more efficient for code purposes since it does not execute the pencil down and up instructions unnecessarily.
Practical case
Make the cat change costumes constantly. Add a 1 second delay to make the costume change a bit slower.
No Comments