+ 1

Whats the difference between these 3 while loops ... Check the code and comments for more

https://code.sololearn.com/WpQA0OoqjNYy/?ref=app

6th Jun 2018, 10:45 AM
Sachin Bhatt
Sachin Bhatt - avatar
6 odpowiedzi
+ 3
In the 3rd section, you output the value after the loop has ended. So you will only see it once. You see 26 because the loop condition is x<=25. Which means it will run again on 25. In the 1st and second section, you output the value everytime in the loop. The big difference is the positioning of the i++; The loop will always execute until i=26. In the first it stops at 25 for you because you write the value before incrementing. When i=25 >output(i) (outputs 25) >i++ (now i = 26 and loop ends) In the second it stops at 26 for you because you write the value after incrementing. When i=25 >i++ (now i = 26) >output(i) (outputs 26) (no more code so loop ends)
6th Jun 2018, 11:06 AM
Andre Daniel
Andre Daniel - avatar
+ 21
In section 1: the i is printed first and then the value gets incremented ... so it prints 20 to 25 In section 2: the i is incremented first and the value of i is printed ... so it prints 21 to 26 In section 3: the while loop runs till the condition becomes false... and then the print statement is executed so after while loop value of i becomes 26...
6th Jun 2018, 11:02 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 3
1st loop: you print the value and then increment it 2nd loop: you increment the value, then prints it 3rd loop: displays the value after loop
6th Jun 2018, 11:02 AM
‎ ‏‏‎Anonymous Guy
+ 1
thankyou so much to all for answering...☺️😊
6th Jun 2018, 11:19 AM
Sachin Bhatt
Sachin Bhatt - avatar
0
answer??
6th Jun 2018, 10:58 AM
Sachin Bhatt
Sachin Bhatt - avatar
0
thanks all for answering
6th Jun 2018, 11:07 AM
Shajad Sheikh
Shajad Sheikh - avatar