문제

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.

도움이 되었습니까?

해결책

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();

다른 팁

You can do:

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

Hope this helps!

You need to declare i outside the for loop.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top