var base_url = 'https://www.bapugraphics.com/';

JavaScript Loops

Loops can execute a block of code a number of times. if you want to run the same code over and over again, each time with a different value.

Instead of writing:

text += bikes[0] + "<br>"; 
text += bikes[1] + "<br>"; 
text += bikes[2] + "<br>";
text += bikes[3] + "<br>";
text += bikes[4] + "<br>";
text += bikes[5] + "<br>";

You can write:

for (i = 0; i     text +=bikes[i] + "
";
}

 

JavaScript supports different kinds of loops:

  • for 
  • for/in 
  • while 
  • do/while 

The For Loop In JavaScript

The for loop is often the tool you will use when you want to create a loop.

Syntax:

for(initializer; condition; iteration)
{
    // Code to be executed
}

The for loop requires following three parts.

  • Initializer: Initialize a counter variable to start with
  • Condition: specify a condition that must evaluate to true for next iteration
  • Iteration: increase or decrease counter

 

The For/In Loop In JavaScript

The JavaScript for/in statement loops through the properties of an object:

Example

var person = {fname:"John", lname:"Doe", age:25}; 

var text = "";
var x;
for (x in person) {
    text += person[x];
}

Contact Details

Mobile Number :
9891 222 738,
9891 50 1300

E-mail : contactbapugraphics@gmail.com

ADDRESS: H-17 / 263, First Floor,Sector 7,
Near Rohini West Metro Station,
Opposite Metro Pillar No. 425
Rohini, Delhi - 110085

Working hours

Day Timing
Monday To Friday 8:00 Am To 7:00Pm
Saturday 10:00 Am To 6:00Pm