0

Can I use already declared variable in for loop ?

Example :- int num = 0; for(int num = 0; num >=10; num++) { }

22nd May 2019, 11:14 AM
Ravindra Kumar yadav
Ravindra Kumar yadav - avatar
1 Odpowiedź
+ 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.
22nd May 2019, 11:20 AM
Matthias
Matthias - avatar