jrliv
1/2/2017 - 9:21 PM

For loop with multiple variables that update.

For loop with multiple variables that update.

for (int up = 1, down = 10; up < down; up++, down--)
{
  Console.WriteLine(up + " " + down);
}
for (int i = 1, sum = 1; i <= 128; i = i * 2, sum += i)
{
  Console.WriteLine("i={0}, sum={1}", i, sum);
}

//  i=1, sum=1
//  i=2, sum=3
//  i=4, sum=7
//  i=8, sum=15
//  i=16, sum=31
//  i=32, sum=63
//  i=64, sum=127
//  i=128, sum=255