Loops are used to repeat blocks of code we put inside them. In this section we'll look at the while, do while. And for loops. These loops all do mostly the same thing but in slightly different ways. The wire loop will repeat all the code written between the curly braces, while the condition between the brackets remains true. When the condition becomes false, the code between the curly braces will be skipped.
If we write a condition that will remain true no matter what the loop will never exit, and we'll call it a forever loop. We can also simply write true between the brackets. And while true is true, which is always the loop will keep repeating. In reality, this forever loop isn't really forever. Batteries do run out and people can also manually stop the program. We can make a while loop that will only repeat the code for a specified number of times.
To do so we create a variable count in this case, and then we increase that variable by one each time the loop executes. The variables value grows each time the loop reaches the end and eventually it will be larger than the value specified in the condition that will make the condition false. And now the loop will exit, meaning it will skip the do something. Another way to increase the value of a variable by one is to use variable plus plus, it is a little shorter and easier to write. In this example, we repeat the two commands forward and turn right four times. Notice that we use global variables for distance, degrees and speed.