+ 1

In while loop, why we first call the "System.out.prinlnt" and after declare the "x++" ?

28th Nov 2016, 12:03 PM
Megii
Megii - avatar
2 ответов
+ 2
Cuz we need to execute our code once before changing variable's value
29th Nov 2016, 10:35 PM
Hamza Muric
Hamza Muric - avatar
+ 1
while(condition){ //do stuff, print etc. //update variable, x++ etc. } In every loop u first do "step" (printig, calculation...) and on the end (before next step) u update variables (x++ in this case) so if x was 1 before u entered loop it will print "1" and then increment x to 2; next step is printing "2" and x++(x=3) and so on, while condition is true...
1st Dec 2016, 12:13 AM
Petar Suvajac
Petar Suvajac - avatar