Examples: . . . In Java
Non-Iterative Loops:
Non-Nested Loops: . . . The Index is a value.
. . . using i, as you would in Algebra, is the most common practise . . .
for (int i = 0; i < LOOP_LENGTH; i++) {
// LOOP_BODY
}
Nested Loops: . . . Differentiating Indices lends to comprehension.
. . . using a descriptive suffix . . .
for (int iRow = 0; iRow < ROWS; iRow++) {
for (int iColumn = 0; iColumn < COLUMNS; iColumn++) {
// LOOP_BODY
}
}
foreach Loops: . . . An Object needs a name.
. . . using a descriptive name . . .
for (Object something : somethings) {
// LOOP_BODY
}
Iterative Loops:
for Loops: . . . Iterators reference Objects. An Iterator it is neither; an Index, nor an Indice.
. . . iter abreviates an Iterators purpose . . .
for (Iterator iter = collection.iterator(); iter.hasNext(); /* N/A */) {
Object object = iter.next();
// LOOP_BODY
}
while Loops: . . . Limit the scope of the Iterator.
. . . commenting on the loops purpose . . .
/* LOOP_DESCRIPTION */ {
Iterator iter = collection.iterator();
while (iter.hasNext()) {
// LOOP_BODY
}
}
This last example reads badly without comments, thereby encouraging them.
It's verbose perhaps, but useful in scope limiting loops in C.