Scope of variable in if in loop

I think because the compiler isn’t able to figure out that the i==1 branch of the if (which defines b) always executes first, so at compile-time it thinks that it’s possible that b is not defined yet in the else branch. See below for the correct answer.

2 Likes