for loop statement 3 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

for loop statement 3

using pre increment gave the result as the post increment post increment i for (i=1; i<=5; i++) { document.write(i + "<br />"); pre increment i will give same results for (i=1; i<=5; ++ i) { document.write(i + "<br />");

29th May 2017, 10:02 PM
Abdulhadi Alhamad
2 Answers
+ 6
That is because they differ where they are assigned to some variable... x = y++ // y is assigned to x, then incremented x = ++y // y is incremented then assigned to x. However, when they are on a single line, they would act the same... y++ x = y // y is incremented on first line and assigned on second ++y x = y // y is incremented on first line and assifned on second.
29th May 2017, 11:19 PM
Gami
Gami - avatar
0
Thanks
29th May 2017, 11:26 PM
Abdulhadi Alhamad