Python - Loops

A loop statement allows us to execute a statement or group of statements multiple times.

You may encounter situations, when a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.

Given below is the general form of a loop statement in most of the programming languages −

Loop

 

Python programming language provides the following types of loops to handle looping requirements.

  • while loops
  • for loops
  • Nested loops

Loop Control Statements

Now that we have seen a few Python loops in action, its's time to take a look at two simple statements that have a purpose only when nested inside loops- the break and continue statements.

Python supports the following control statements.

  • break
  • continue
  • pass
  • loop ese block