In these examples why is a first assigned value 0 before the increment or decrement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In these examples why is a first assigned value 0 before the increment or decrement?

12th Aug 2017, 5:55 AM
HC Pieck
HC Pieck - avatar
5 Answers
+ 7
What examples?
12th Aug 2017, 6:04 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
usually it's like this for (var i = 0; i < 10; i++) { // code here } this means i counts from 0 to 10 i = 0 is the first time '// code here' is executed i = 1 is the 2nd time ... i = 9 is the 10th time (last time) i = 10 doesn't match the condition '< 10' so the for loop is done. you could also start counting from 1, but for it to excecute 10 times you'd have to write either (var i = 1; i <= 10; i++) or (var i = 1; i < 11; i++) which might confuse you let me know if this was your problem
12th Aug 2017, 1:33 PM
Rcknmrty
Rcknmrty - avatar
+ 1
well b isn't defined. if you mean y, then yes x is 11
12th Aug 2017, 2:31 PM
Rcknmrty
Rcknmrty - avatar
0
the increment decrement exercise state x=0, y=10; x=y++. If we're going to increment y to produce x why assign x value 0 in the first place?
12th Aug 2017, 6:37 AM
HC Pieck
HC Pieck - avatar
0
OK I got it yes thanks! I was just wondering is it really necessary to assign a value to x? Is this incorrect: y=10; var x=b++; result: x=11?
12th Aug 2017, 1:51 PM
HC Pieck
HC Pieck - avatar