+ 3

Why Value Increased In do... While loop?

please see my code Add It all or something like that code and kindly tell me why value of variable sum_of_all increased in do while loop

2nd Feb 2017, 5:06 PM
Bruh
3 Respuestas
+ 3
Your code needs some changes. After the completion of 'for loop', sum_of_all becomes 5050 and j becomes 101. 'While loop' checks (j<=till) i.e. (101<=100), which is false. So, while loop is not executed and 'System.out.println' prints previous value of sum_of_all, which is 5050. 'Do while loop' adds j (101) to sum_of_all (5050) which results in 5151 and increments j to 102. So, 5151 is printed. To correct this, you have to add j = 0; sum_of_all = 0; before while, do while loops. Note : I posted this as a comment to your code (Sum of All Using All Loops).
3rd Feb 2017, 3:35 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 2
Post the code so I can help.
2nd Feb 2017, 5:34 PM
Ali Emir Kızıl
Ali Emir Kızıl - avatar
0
okkk
5th Feb 2017, 5:16 PM
Dnyaneshwar Mali
Dnyaneshwar Mali - avatar