#164 – for Loop Clauses Can Contain Lists of Statements

Both the initialization clause and the iteration clause of a for loop can consist of multiple statements, separated by commas.

For example, you could initialize two different variables in the initialization clause and then increment one variable and decrement the other in the iteration clause.

            // Set reverse diagonal of matrix
            for (int i = 0, j = 9;
                 i < 10;
                 i++, j--)
            {
                nums[i, j] = 1;
            }
Advertisement