+ 1

# Question of the Day

Can someone help me understand why the output to this block of code is 111? loop=0; for(x=0;x<=2;x++) { ++loop; document.write(loop-x); }

1 Answer

+ 14

First loop:
- loop gets incremented to 1, x is 0
- outputs loop - x, which is 1
Second loop:
- loop gets incremented to 2, x is 1
- outputs loop - x, which is 1
Third loop:
- loop gets incremented to 3, x is 2
- outputs loop - x, which is 1