+ 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
3 Réponses
+ 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).
+ 2
Post the code so I can help.
0
okkk