void Start()
{
for (int a = 1; a < 2; a++)
{
Debug.Log(a);
}
}
According to the above repetition, I thought the output value would be 2, but it came out as 1. Is it not applied to the output value because it does not conform to the conditional expression after the value a becomes 2?
unity visual-studio
You're right.
The for repeat statement is a for (initial expression; conditional expression; increment/decrease expression)
configuration.
The initialization formula runs only the first time. Evaluate the conditional expression before every loop starts, and execute the in-block code only when the conditional expression is true
. The increment/decrease expression runs at the end of each loop.
Therefore, in the second loop, a
becomes 2 and a < 2
becomes false
to escape the repeat statement.
© 2024 OneMinuteCode. All rights reserved.