if (expression) { # condition
__________________;
__________________;
} elsif (expression) {
__________________;
__________________;
} elsif (expression) {
__________________;
__________________;
} else {
__________________;
__________________;
}
unless (expression) { # condition
__________________;
__________________; # do if false
__________________;
} else {
__________________;
__________________; # do if true
__________________;
}
while (expression) { # condition
__________________;
__________________; # do if expression is true
__________________; # then go back and recheck expression
}
until (expression) { # condition
__________________;
__________________; # do if expression is false
__________________; # then go back and recheck expression
}
foreach $i (@some_array) {
__________________;
__________________; # iterate over array elements
__________________;
}
foreach (1 .. $n) {
__________________;
__________________; # repeat $n times
__________________;
}
Example: print all even numbers between 4 and 12:
for ($i = 4; $i <= 12; $i += 2) {
print "$i\n";
}
Same as:
my $i = 4; # set initial state of $i
while ($i <= 12) { # condition to test $i
print "$i\n";
$i += 2 # modify $i
}