Update two looping variables in for loop in CSharp
Description
The following code shows how to update two looping variables in for loop.
Example
using System;/*from w ww. j a va2s . c om*/
public class MainClass
{
const int StartChar = 33;
const int EndChar = 125;
const int CharactersPerLine = 5;
static public void Main()
{
for (int i = StartChar, j = 1; i <= EndChar; i++, j++)
{
Console.Write("{0}={1} ", i, (char)i);
if (0 == (j % CharactersPerLine))
{
Console.WriteLine("");
}
}
}
}
The code above generates the following result.