Answer the question
In order to leave comments, you need to log in
Why does the loop output 0 at the very beginning?
int i = 0;
for(; i<5; i++){
Console.Write(i);
}
Answer the question
In order to leave comments, you need to log in
In this case, there is no difference. Since this operation (i++ or ++i) will be executed at the end of the iteration.
And in the example below, there is already a difference:
int i = 0;
for (; i < 5;)
{
Console.Write(++i); // 12345
// i = i+1;
// Console.Write(i);
}
Console.WriteLine();
i=0;
for (; i < 5;)
{
Console.Write(i++); // 01234
// Console.Write(i);
// i = i+1;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question