Increment and decrement is the most useless syntax in java. Why are we need it while we have addition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Increment and decrement is the most useless syntax in java. Why are we need it while we have addition

I'm not native and not good at english 👌👌

24th Apr 2018, 4:11 PM
Huỳnh Quốc Tuấn
Huỳnh Quốc Tuấn - avatar
3 Answers
+ 1
for(int i = 0; i < n; i++) if(++i == g) i--; now without pre and post incrementation and decrementation: for(int i =0; i < n; i = i + 1) if((i = i + 1) == g) i = i - 1; and you cant even talk about pre of post here since you only want addition. For loop are also useless cause you can just copy and paster your code N times tho, right?
24th Apr 2018, 4:43 PM
Paul
0
I thought it must have been ++i, mustn't it
25th Apr 2018, 4:07 AM
Huỳnh Quốc Tuấn
Huỳnh Quốc Tuấn - avatar
0
it is all about pre and post increment that is crucial and you just simply can't do some of them in one line using addition or substraction, so that is why they are uaeful
25th Apr 2018, 5:47 AM
Paul