Let’s Learn Loops!
A While Loop
We will use the same project we did in the for loop example to learn how while loops work. So like in the for loop we
need to have a conditional that needs to be met while
the loop runs. We can use the same condition we used in the
previous example.
Now we can’t just print out i, or it will not do anything other than print out 1 forever, but in the body of the loop,
or the space between the two curly braces {}
, we can do something similar to what we did above with the for loops.
You can see in the body we print out i and then increment it by two so that when the loop runs again it will print out 3, 5, 7, and so on.