JavaScript Loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

JavaScript Loops

I was just wondering if there was a way to do a loop and stop on a certain number but only write that number that you chose. Example for(var i = 0;i<20;i++){ document.write(i); } so here is a example of a for loop but is there a way to say... land on 15 and only document 15 so instead of going 1234567891011121314151617181920 I could just land on 15 and 15 only If anyone has answers it would be greatly appreciated and thank you

11th Apr 2018, 11:38 PM
Bradley
1 Answer
+ 4
you could wrap an if statement inside of the loop like if(i == 15) { document.write(i); }
11th Apr 2018, 11:42 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar