The syntax of a for loop is ideal when you know how many times you want a loop to run. What if we don’t know how many times a loop should run in advance? In situations when we want a loop to execute an undetermined number of times, while loops are a great choice. We start our loop with the keyword while followed by our stopping condition, or test condition. This will be evaluated before each round of the loop. While the condition evaluates to true, the block will continue to run. Once it evaluates to false the loop will stop. In the following video, we will show you how to write a while loop.
If you get stuck or need assistance, you can click the button below to connect with a tutor.
For additional questions or technical support, email email@example.com.