+ 1
On the while loops part postfix and prefix
i came across a good that dosenr change if you swtich n++ with ++n can someone explain this to me. i was reading while loops on the second chapter
2 odpowiedzi
+ 6
For example :
int x = 1;
if we write postfix : x = x ++; it's value doesn't change, because x gets it's value (x=1) before increasing it.
x = ++x; in this case x gets the value after increasing (x = 2) it.
If you use while loop for example :
x = 1;
while(x < 2){
x = x ++;
}
it causes an infinite loop. because the value of x doesn't change as I said. if you use ++x vice versa.
+ 1
its on conditionals and loops chapter on the useing while loops lesson on the last part of the lesson