while Loop in JavaScript

The while loop in JavaScript, is used to continue executing some block of code, until the given condition evaluates to be false. For example:

HTML with JavaScript Code
<!DOCTYPE html>
      let num = 5, i = 1;
         document.write(num, " * ", i, " = ", num*i, "<BR>");

JavaScript while Loop Syntax

The syntax of while loop in JavaScript, is:

while(condition) {
   // body of the loop

Note - Do not forgot to update the loop variable. Otherwise the loop may go for infinite execution.

JavaScript Online Test

« Previous Tutorial Next Tutorial »