Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
it's not just about loop if there is just the increment operator with a variable and is not relative then it won't make changes whther it's postfix or prefix.. like for example 1: int x=2; x++; int y=x; // y will be 3 now take the same example2: int x=2; ++x; int y=x; //y will be 3; now take another example 3: int x=2; int y=++x; // y will be 3 and x also will be 3 now take same example 4: int x=2; int y=x++; //y will be 2 and x will be 2 but the x will change to 3 after statement terminates.. System.out.println(y); System.out.println(x); now in example 1 and 2 the value of x++ and ++x are not related to any other variable.. but in the example 3 and 4 the value of x is related to y directly, the increment affects the value of y there itself
13th Jul 2017, 3:28 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar