0
In these examples why is a first assigned value 0 before the increment or decrement?
5 Antworten
+ 7
What examples?
+ 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
+ 1
well b isn't defined.
if you mean y, then yes x is 11
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?
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?