Hello All,
I have a very simple and a silly doubt
. why can't we declare a new variable inside for loop. Like
for(int i=0;i<5;i++)
int j=10; //No enclosing braces {}
After some analysis, I thought
int j=10; => int j; j=10; //Two separate steps
and since there is no block defined the above one is interpreted as
for(int i=0;i<5;i++)
{ int j;}
j=10; // Using un declared variable
Is my understanding correct, if so why should compiler separate both declaration and initialization.