Introduction to Loops

Get yourself introduced to loops and learn about their different types in Perl in this lesson.

We'll cover the following

What are loops?

Loops allow a programmer to execute the same block of code repeatedly instead of re-writing code that needs to be executed multiple times.

Conditional statements will be used again in the loops. You may recap the conditional statements if you want to refresh the concepts.

The following figure illustrates how loops work:

Types of loops

There are many types of loops:

  • while loop
  • do...while loop
  • for loop
  • foreach loop
  • until loop