New course! Every coder should learn Generative AI!
Try a free lesson+ 1
help me understand this code in c#
Could you help me understand this code : int x = 1; while (x++ < 5) { if (x % 2 == 0) x += 2; } // output 2 ------------------------------- and what different between while(++num < 6) and while(num++ < 6)
1 Answer
+ 1
Hi,
the thing with "++num" and "num++" is called pre and post increment.
Pre increment(++num) means the value of num is incremented by 1 (num + 1) BEFORE the statement is evaluated.
Post increment(num++) means the value of num is incremented AFTER the statement.