Looping Directives: foreach, for

Learn about the foreach and for looping directives.

We'll cover the following...

The looping directives

Perl provides several directives for looping and iteration.

The foreach and for directives

The foreach-style loop evaluates an expression that produces a list and executes a statement or block until it has exhausted that list:

Perl
foreach (1 .. 10) {
say "$_ * $_ = ", $_ * $_;
}

This example uses ...