0
Can I use already declared variable in for loop ?
Example :- int num = 0; for(int num = 0; num >=10; num++) { }
1 Answer
+ 4
Yes.
But you don't need int, you could just write num=0 or even only num in the first slot in this case.
Also your loop in this example wouldn't even start, since the condition is violated before the first run since 0>=10 is false.
Maybe you wanted num<=10
Such things can be easily checked in the Code Playground.