---
title: "Better possibility to use while and for loop"  
description: "Better possibility to use while and for loop"  
author: "Anonymous User"  
published: 2021-07-19  
updated: 2021-07-19  
canonical: https://www.mindstick.com/forum/156519/better-possibility-to-use-while-and-for-loop  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Better possibility to use while and for loop

Which should I use While [Loops](https://www.mindstick.com/forum/161927/explain-the-python-while-loops-with-example) vs. For Loops in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by 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.

\


---

Original Source: https://www.mindstick.com/forum/156519/better-possibility-to-use-while-and-for-loop

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
