+ 1
While Loop explanation
Why would you code it this way: var i=0; while (i<=10) { document.write(i + "<br />"); i++; } and: var x = 1; while (x <= 5 ) { document.write(x + "<br />"); x = x + 1; } and not this way: var x = 1; while(x<=5){ document.write(x++); } why would I add the extra line under the document.write function like they did in the lesson? Thank you!!
2 odpowiedzi
+ 3
In- or decrementing on the fly can lead to confusion and funny bugs if you don't know what you're doing.
If you do, it doesn't really matter, right?
The tutorials are addressing beginners, so I suppose they want to keep it simple.
+ 2
I'm also a beginner, To me, the third option looks much more simpler.. I don't understand what is the different?
Also, what does the + do?
document.write(x + "<br />");
Why can't you write it as:?
document.write(x "<br />");
The line after thy added the +1 anyway
x = x + 1;