On the while loops part postfix and prefix | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

1st Jan 2018, 6:17 PM
Lord Awesome
Lord Awesome - avatar
2 Answers
+ 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.
1st Jan 2018, 6:58 PM
Nodirbek Raxmatullayev
Nodirbek Raxmatullayev - avatar
+ 1
its on conditionals and loops chapter on the useing while loops lesson on the last part of the lesson
1st Jan 2018, 6:21 PM
Lord Awesome
Lord Awesome - avatar