Lesson 10. Programming: LOOPS
- Obtener enlace
- X
- Correo electrónico
- Otras aplicaciones
23/04/21
We are going to talk about Loops, which is the third basic knowledge children need to know in order to have a basic approach towards programming. Loops in programming are used to make the program repeat the code several times, it is very useful for animations and exercises!
To introduce the concept of "loops" we can tell the children they are like setting the table. One set of actions could be to set a plate, a glass, a fork and a knife in the table, but if you want to set the table for 4 people you can just repeat that set of actions 4 consecutive times.
We can practice this basic concept by making use of Primary Code, since the coding is already done, and children will only need to understand it. Then, we can explain this same concept of repeating a certain action a number of times.
To make the concept a little bit more hard we can add variables into the mix. In the following picture we have three variables: a, b and i (increasement). When the value of i is less than 5, the program repeats the following actions: adding one to a and adding a to the variable b. The process repeats and the variable i increases with every loop.
In the following step, it is almost the same procedure, except i will now substract one unit. In this example, every time i is bigger than 9 the program will substract 1 to the variable i.
In the following loop, the condition (i being smaller than 0) never fulfills, the loop does not take place:
Now we can switch to Scratch we can also do these same examples. Actually in this software, loops are represented by the block "repeat". We can use this block and fill it with different blocks so it repeats an action the number of times we want it to. And with the next code we will: Make the cat start in the position x=0 y=0 when the Green Flag is clicked. Walk 10 steps. And repeat this action 10 times.
- Obtener enlace
- X
- Correo electrónico
- Otras aplicaciones
Comentarios
Publicar un comentario