We know that, somehow, we use i and j variables in loops very commonly. If one need a double for loop, it’s very likely to use something like the following:
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
// do some stuff...
}
}
However, if I need a third for loop in these loops, I don’t have any naming convention for the third iterator. I, likely use the following variables: r, k, ii, jj etc…
Is there a naming convention for the third (and so on…) loop’s iterator?
The most important thing for readability should be obvious names.
i and j aren’t the most obvious, but may be ok for simple cases. Consider this (admittedly somewhat ill thought out) example;
vs
It’s quite easy to see which makes more sense to read. But while we’re at it, how about making it even more readable while eliminating your naming problem even more;
Maybe overkill/verbose for this simple loop, just wanted to make the point that there are more ways you can deal with the naming problem for nested loops than just finding unique names.