while Loop in JavaScript – Tutorial 20

Hi friends, in previous JavaScript Tutorial we have seen for loop. In today’s JavaScript tutorial, we are going to learn one more loop in JavaScript which is while loop. While loop in JavaScript does the same job like for loop with some little changes.

The main difference between while and for loop is that we directly write some condition in while loop unlike for loop. In for loop, we first initialize some variable and then we increment it for a number of times. In while loop, we already have a variable and we just check the condition for it. while loop stops only when a condition becomes false.

Let us see one simple example of for loop in JavaScript for clear understanding. In this example, we will print a table of 21 using a while loop. It’s very simple to understand.

while loop in JavaScript
while loop in JavaScript

Download: Click here to see the output of this program in your browser. Right-click and select Save Link as to download the file.

In next JavaScript tutorial, we are going to learn do while loop in JavaScript. If you liked this article then share it with your friends. Like our facebook page and subscribe to our newsletter for future updates. If you have any questions, feel free to ask in the comment section below. Have a nice day!

Also read:  How to create HEX file in keil for 8051 microcontroller

Published by

Mayuresh Joshi

Mayuresh Joshi a web geek and founder of MyClassBook, a popular educational blog since 2012. He has completed his B.Tech (Instrumentation Engg.) from SGGSIE&T, Nanded. He loves to write on electronic projects, SharePoint and other current technologies.

Leave a Reply

Your email address will not be published. Required fields are marked *