| Two, actually. You didn't need to declare the loop variable in the first statement of the loop. Doing so is a fairly new feature of ANSI C++ and means the loop variable only has scope within the loop itself, and ceases to exist once the loop ends.
Also, commas can have their place in a for loop. For example, let's say you're doing something requiring looping with a pair of C-style strings. If you wanted to use a for loop to do it, your loop might look something like this:
for (char *first = str1, *second = str2; *first != '\0'; ++first, ++second)
{
// body of loop
}
Here, the comma operator is being used to do two things at once in a single statement: initialize the loop variables, and increment them.
However, this kind of thing can't be done to eliminate loop nesting for multiple-dimensional array (i.e., matrix) processing; you still need the nested loops for correctness. |