Loops

Introduction to Loops

Loops in Python allow you to repeatedly execute a block of code as long as a condition is true or until a specific condition is met. Loops are essential for automating repetitive tasks. Python has two types of loops:

  1. for loop
  2. while loop

You can also control the flow of loops using:

  • break: Terminates the loop.
  • continue: Skips the current iteration and moves to the next.
  • pass: Does nothing and is used as a placeholder.