Conditional Loops
Conditional loops, also known as while loops, repeat until the condition is met. All instructions inside this loop will run for each repeat of the loop.
Key Points
Conditional loops run until a condition is met.
The condition can use logical operators to have multiple conditions.
Conditional loops often create their own index by using a counter.
Using a while loop
A simple while loop can be used to ensure data is accurate before continuing.
In the below example, the a variable is created call counter and starts at 0.
The while loop checks to see if counter is less than 5.
While it is, the counter increases by 1 for each loop.
When the counter is greater than or equal to 5, the loop ends.
counter = 0
while counter < 5:
counter = counter + 1