0
What is the final value of i in this code ?
for(i=1;i<10;i++). no statement inside! i just want to know whether the value of i will be 9 and the loop will end because it runs only less than 10 times OR the value of i will become 10 because of that i++ but the loop will run again only 9 times. someone told me that after for and while and do while loop the value of i becomes one more higher than the condition so the loop execute required no. of times only but with a higher value of i which terminates the loop
3 Answers
+ 1
Its value will be 10
because in for loop , first variable iis initialize than checked condition and than loop's run if it's true.
Now every time it will increment variable i than check condition when i value will be 9 loop will run and increment i value to 10.
Now condition will hold false and loop will stop running.
Hence i value will be 10.
Hope this helpsâșïžâșïž.
+ 1
the value of i will be 10 because if it was 9 the condition would evaluate to true and the loop would continue. since the loop only stops when i isn't less than 10, i will have to reach 10 for the loop to stop.
0
thnx hinanwi and meet, i got the doubt resolved