Why is this equivalent to 5? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
2nd Jun 2019, 3:28 PM
Pikachu
Pikachu - avatar
3 Answers
+ 5
The for loop doesn't do anything. Note the empty curly brackets. It's an empty statement, just like for(int i = 0;i<7;++i); // <= note the semicolon at the end. Also, the variable i in the for loop is not the same variable that is used outside of the loop, because it was declared in the for loop. So the outer variable i isn't affected in any way. If you change it like this: for(i=0; i<7; ++i) {} it will actually affect the outer variable i.
2nd Jun 2019, 3:35 PM
Anna
Anna - avatar
+ 4
5, because loop is not for i
2nd Jun 2019, 3:46 PM
Muhammad Rashid
Muhammad Rashid - avatar
+ 1
thanks
2nd Jun 2019, 3:37 PM
Pikachu
Pikachu - avatar