سؤال

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