c# for statement variable usage outside of the statement [closed]
-
15-06-2021 - |
質問
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;
所属していません StackOverflow