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 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.
22nd May 2019, 11:20 AM
Matthias
Matthias - avatar
Hot today
.
1 Votes
What?
0 Votes
HTML
0 Votes
Web
0 Votes
Quiz duel
0 Votes
FRC Coding?
1 Votes
help
0 Votes
AI
2 Votes
APIs
1 Votes