Perl standard
In Perl, the standard variable name for an inner loop is $_. The for, foreach, and while statements default to this variable, so you don't need to declare it. Usually, $_ may be read like the neuter generic pronoun "it". So a fairly standard loop might look like:
foreach (@item){
$item_count{$_}++;
}
In English, that translates to:
For each item, increment it's item_count.
Even more common, however, is to not use a variable at all. Many Perl functions and operators default to $_:
for (@item){
print;
}
In English:
For [each] item, print [it].
This also is the standard for counters. (But counters are used far less often in Perl than in other languages such as C). So to print the squares of integers from 1 to 100:
for (1..100){
print "$_*$_\n";
}
Since only one loop can use the $_ variable, usually it's used in the inner-most loop. This usage matches the way English usually works:
For each car, look at each tire and check it's pressure.
In Perl:
foreach $car (@cars){
for (@{$car->{tires}}){
check_pressure($_);
}
}
As above, it's best to use longer, descriptive names in outer loops, since it can be hard to remember in a long block of code what a generic loop variable name really means.
Occasionally, it makes sense to use shorter, non-descriptive, generic names such as $i, $j, and $k, rather than $_ or a descriptive name. For instance, it's useful to match the variables use in a published algorithm, such as cross product.