-3
for (i = 0; i < 14; i++)
{
     //display data here
}

Console.WriteLine("{0}", i);
Console.ReadLine();

I want to display the amount of times total i iterated outside the for statement so it only displays ONCE.

Dan
  • 185
  • 2
  • 2
  • 12
  • 1
    You haven't declared the variable `i` in the for iterator, so your code could be compiled only if you declare the variable before the for. In that case the WriteLine after the for loop works as expected. So what's the problem? – Steve Jun 17 '12 at 20:55
  • Not sure the downvotes are warranted here... – Kirk Woll Jun 17 '12 at 21:49

4 Answers4

1

You can do:

int i = 0;
for(;i < 50; i++)
{
    // Do some stuff
}
Console.WriteLine(i.ToString());

Hope this helps!

matthewr
  • 4,679
  • 5
  • 30
  • 40
1

Just add an i declaration before your for loop:

int i;
for (i = 0; i < 14; i++)
{
     //display data here
}

Console.WriteLine("{0}", i);
Console.ReadLine();
Douglas
  • 53,759
  • 13
  • 140
  • 188
0

You need to declare i outside the for loop.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

define variable i before the loop and initialize it to 0;

dzendras
  • 4,721
  • 1
  • 25
  • 20