for ($i = 0; $i < 10; $i++)
{
print $i, "\n";
}
|
|
While statements are easy:
$i = 0;
while ( $i < 10 )
{
print $i, "\n";
$i++;
}
If statements are similarly easy:
for ($i = 0; $i < 10; $i++)
{
if ($i != 5)
{
print $i, "\n";
}
}
The boolean operators work like they do in C:
If you have an array, you can loop through it easily with foreach:
@a = ('dog', 'cat', 'eel');
foreach $b (@a)
{
print $b, "\n";
}
Foreach takes each element of the array @a and places it in $b until @a is exhausted.
More Options: