Pssst...use your keyboard arrows to turn the page!
Helloooooooo, coders! In this chapter, we are going to learn about an important coding concept called loops. Loops are often used to create animations!
An animation - like the ones you see in movies and on TV – are made by showing a bunch of still images one after the other. When this is done really fast, then it looks like the characters are really moving!
When we create animations, we will have to repeat the same instructions – like showing our sprite’s next costume – over and over and over again.
But here’s the problem: dragging out the same instructions tens, hundreds, or thousands of times would be way. Too. Much. WORK!
For example, let’s pretend that we want to make a gigantic banana split, and we need our friend to help us peel 50 bananas.
Now, our friend happens to be from another planet, and for some reason, the ONLY sentence she understands is “peel a banana, please!” So if we had to write instructions for our friend, we would need to write that down 50 times for her to peel all 50 of the bananas!
But writing that command down 50 times is going to take a LONG time, and it’ll be REALLY boring too. Thankfully, to speed things up, we can use something called a loop!
In programming, a loop is something that allows us to repeat the same command as many times as we want.
To use a loop, we would just write, “repeat 50 times: peel a banana please!” and our friend will peel one banana after another until she’s peeled 50 bananas.