Let’s start with basics- beep a single tone on the piano on repeat to learn about loops!
The code in the editor below already works Just plug in your Code Piano and press upload to see what it does! Tinker with it and make changes to see what each line of code controls.
Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!
Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!
These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.
New Concept: Short-term variables & scope
When you write ‘i =…’ in the ‘for’ loop, you’re creating a new variable. That variable is used for one purpose: keeping track of how many times the ‘for’ loop has run. Because it has such a limited purpose, it’s typical to just use ‘i’ as the name, instead of typing out ‘counter’ or ‘forLoopVariable’ or something that might be more descriptive, but harder to type out.
In this program, you are creating the ‘i’ variable twice, once for each ‘for’ loop. Because the variable is created inside the ‘for’ loop, it only exists inside that ‘for’ loop and it gets recreated each time the ‘for’ loops run. This concept that the variable can ‘exist’ some places but not others within the same program is called the variable’s scope.