while loop is similar to an
if statement: it executes the code inside of it if some condition is true. The difference is that the
while loop will continue to execute as long as the condition is true. In other words, instead of executing if something is true, it executes while that thing is true.
Line 6 decides when the loop will be executed. So, “as long as
count is less than
5,” the loop will continue to execute. Line 8 increases
count by 1. This happens over and over until
Change the loop so that it counts from
0 up to
Be careful not to alter or remove the
count += 1 statement. If your program has no way to increase
count, your loop could go on forever and become an infinite loop which could crash your computer/browser!