+ 12

can you answer what is the difference among the three nearly same code? (good explanation please)

for (var x=1; x<=5; x++) { x=x+10; document.write(x); } //output:11 for (var y=1; y<=5; y++) { document.write("<br>"+y); y=y+10; } //output:1 for(var z=1;z<=5;z++){ z=z+10; } document.write("<br>"+z); //output:12

15th Nov 2017, 4:46 AM
Md Shabukta Haider
Md Shabukta Haider - avatar
4 Respostas
+ 14
but the output of 2nd code is //1, how it increments??? :O code3 is 12, because document.write is outside the loop? & code 1 was inside of curly brackets??
15th Nov 2017, 5:41 AM
Md Shabukta Haider
Md Shabukta Haider - avatar
+ 14
oh Right :)
15th Nov 2017, 10:47 AM
Md Shabukta Haider
Md Shabukta Haider - avatar
+ 7
1. It adds x by 10 then prints it. 2. It prints y with a new line. Then it increments it by 10. 3. It adds z by 10. Then increment it by one after the iteration. Then it prints it out with a new line at the beginning.
15th Nov 2017, 4:54 AM
qwerty
qwerty - avatar
+ 7
Because it prints it first, then adds it.
15th Nov 2017, 7:05 AM
qwerty
qwerty - avatar