Introduction
The for loop
The while loop
Nested loops
break and continue
Summary
20. Summary

Instruction

Great, it's time to wrap things up!

  • A for loop can be used with a range:

    for i in range(1, 6):
      ...
  • A for loop can be used to iterate over a string:

    password = 'sfdj3@3d'
    for letter in password:
      ...
  • A while loop looks like this:

    while condition:
      ...

    It executes as long as the condition is true.

  • Instead of

    counter = counter + 1
    you can simply use
    counter += 1

  • The break keyword is used to terminate the whole loop.
  • The continue keyword is used to skip to the end of the current iteration.
  • Loops can be nested.

All right, how about a short quiz now?

Exercise

Click Next exercise to continue.