Looping statements in JavaScript

Looping constructs in JavaScript are similar to the ones available in C language. We have below types of looping constructs in JavaScript.

  1. for loop
  2. for in loop
  3. do .. while loop
  4. while loop

For loop examples

for(var i=0;i<=5;i++)
console.log(i)

var cities = [“Brisbane”,”Perth”]

for(var x in cities){
console.log(cities[x])
}

while loop example
var j = 1;
while(j<=15)
{
console.log(j)
j++
}

 

You may also like...