0
The using of "loops" in real webpage
Would you like to tell me some real condition of using "loops" in webpage. I really wonder because the example just show me about printing number with a range.
3 Antworten
+ 3
Maybe you would want to take input from multiple text fields and apply a certain operation to them before storing it in a database.
Or, you have some data with you and you want to display them in different lines, you would do something like this:
text += cars[0] + "<br>";
text += cars[1] + "<br>";
text += cars[2] + "<br>";
…
text += cars[99] + "<br>";
Instead, you can just write:
for (let i = 0; i < 100; i++) {
text += cars[i] + "<br>";
}
The point is that using loops is an efficient way to do something repeatedly, instead of manually writing all the code.
Don't worry about its application just yet, that's something you'll learn along the way :)
0
👍
0
👍