![]() Or in other words: a data type than can be enumerated (counted in whole numbers and with fixed increments). For each time we go through the loop, increase A by one (A++)Ĭounting in a “for” loop can only be done with whole numbers (byte, int.The parameters we need to give the “for” statement are: Serial.print ( "Switch lights on for light " ) If you’d like, you can forget about the lingo right away though. We cannot use this pseudocode in our program, but it helps writing down the steps we want to take in our program, or to explain code in a more human readable way. Pseudocode is basically writing a program (on paper for example) is a more human like language, yet using “constructs” that look like the ones we use in our programming language of choice. Writing program code like that is also called “ Pseudocode“. Quite often, variables are used for counting, so our previous statement could be: Loops are used to repeat certain instructions repeatedly A bonus is that when we have to change our code to more or less lights, we simply modify one single number. It’s not just for our typing that this saves space – your source code will be shorter and easier to read, but also the compiled program for the Arduino will be much smaller, and maybe even faster. ![]() Tada! We’ve just made a loop, which saves us writing down the (almost) same sentence over and over again.Ĭan you imagine how much typing that would save us if we would have to count to 1,000 ? So we repeat the same instruction (switch light ON), for each of the 5 lights.Ĭount from 1 to 5, and for each of the numbers, Switch Light ON. Say we have 5 lights, each with their own switch. The most common application is when we have to repeat a certain set of instructions repeatedly, either based on conditions or based on counting. The purpose of Loopsīefore we start working with loops, we should probably understand when and where we would be using loops. A complete overview of this course can be found here: Course Overview.
0 Comments
Leave a Reply. |