Better possibility to use while and for loop

Which should I use While Loops vs. For Loops in JavaScript?

Last updated:7/19/2021 5:35:34 AM

1 Answers

Ethan Karla
Ethan Karla

There is no difference between while and for loops in executing but as a developer there are some scenario which make them differ on a executing purpose.

For loops are great for doing the same task over and over when you know ahead of time how many times you'll have to repeat the loop.

On the other hand, while loops are ideal when you have to loop, but you don't know ahead of time how many times you'll need to loop.


Answer