the while loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

the while loop

var x = 1; (x <= ) { document.write(x + "<br />"); x = + 1; } why is it x = x + 1 ???

9th Sep 2016, 11:07 PM
Alejandro Cortez
Alejandro Cortez - avatar
2 Answers
+ 5
var x = 1; while (x <= 5) { document.write(x + "<br>"); x = x + 1; } You want to print x's values from 1 to 5 (ie 1 2 3 4 5), so you need to increment x by one each loop.
9th Sep 2016, 11:19 PM
Zen
Zen - avatar
0
sorry for the late response. thank you I appreciate it!
8th Dec 2016, 2:31 AM
Alejandro Cortez
Alejandro Cortez - avatar