0

What sense make it to use before or after?

"Increment ++ The increment operator increments the numeric value of its operand by one. If placed before the operand, it returns the incremented value. If placed after the operand, it returns the original value and then increments the operand. Decrement -- " What for a sense does it make to write the operators before or after? Is there any example in programming in which it could make sense?

6th Jun 2017, 10:33 AM
Elias Fzada
Elias Fzada - avatar
5 odpowiedzi
6th Jun 2017, 11:00 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 6
Thirth code worked reversly while Fourth code worked straight (because I added .reverse() method) but as you can saw It's too long And Fifth I gonna add later This fifth connect to thirth which is useful and make your website faster @Madera Oxidada Wow Really?! I must test it later!
11th Jun 2017, 11:49 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
0
Pre increment is faster than post increment, so if you dont care which you use, you should always use ++x. Im never going to get bored saying this, i think everyone should know it.
6th Jun 2017, 2:23 PM
Madera Oxidada
Madera Oxidada - avatar
0
Than you guys! And @veryhard : thanks for showing but unfortunately I didn't get the last code in your example :/
11th Jun 2017, 9:29 AM
Elias Fzada
Elias Fzada - avatar
0
@notsohard Yes. Pre increment just adds one to the variable, while post increment makes a copy, and then adds one to the original.
11th Jun 2017, 2:38 PM
Madera Oxidada
Madera Oxidada - avatar