Loops


Loops: loops are that code who run continuous till condition is true, we can implied loops with arrays and conditions so they are very useful when we are dealing with large number of data.

There are various type of loops available but we talk here about 3 most important loops.

Loop 1 : For loop


Syntax :

for (var i = 0; i < Things.length; i++) {
Things[i];
}; // Run loop till condition is true

Example: Rum loop till no 10.

for (var i = 0; i <=10; i++) {
console.log(i);
};
Another Example :

var person = ["Jenny","Jeffery","Jaminy","James"];
for (var i = 0; i < person.length; i++) {
console.log(person[i]);
};


Loop 2 : While loop - Run loop only when condition is true.


Syntax:

while(condition==true) {
run loop
};

Example:

var i = 0;
while(i<=10) {
console.log(i);
i++;
}

Another Example:

var person = ["Jenny","Jeffery","Jaminy","James"],
i = 0;
while(i console.log(person[i]);
i++;
}


Another Example --> Remove Every time one person name by using array

var person = ["Jenny","Jeffery","Jaminy","James"];
while(person.length > 0) {
var removeItem = person.pop();
console.log(removeItem);
}



Loop : 3 do while loop

var person = ["Jenny","Jeffery","Jaminy","James"];

do {
var removeItem = person.pop();

console.log(removeItem);
}while(person.length > 0);


Wconcert India © 2015   ·   All Rights Reserved

Free Web Hosting