Welcome to the lesson on Python While Loops
While Loops
With the while loop we can execute a set of statements as long as a condition is true.
Example: Print i as long as i is less than 6:
Caution: Remember to increment i, or else the loop will continue forever.
Break statement
Some Examples: With the break statement we can stop the loop even if the while condition is true:
Continue Statement
With the continue statement we can stop the current iteration, and continue with the next:
Some Examples: Continue to the next iteration if i is 3:
Else statement
With the else statement we can run a block of code once when the condition no longer is true:
Some Examples: Print a message once the condition is false:
End of Python While Loops
You have learned While Loops in simple terms. Let's proceed on to Quiz.