JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops For Loops

Immanuel Jaeggi
Immanuel Jaeggi
5,164 Points

When to use conditional statements, while, do...while, and for loops.

Can someone explain the above by posting one simple example for each of the loops and conditional statements? It would be nice if your example is a real-world challenge, like asking a client to fill out a form for instance.

I understand how each one works individually, but when it comes to decide which one to implement when I actually code a website it gets tricky.

1 Answer

Loops are mostly all the same. They are used to repeat a block of code. Use for loops when you know how many times you want to repeat something, and while loops when you're not sure.

Let me know if this helps here