DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

for Loop,while loop ,do-while loop,forEach Loop and forin loop

for loop

console.log("for loop");

for(let i=0;i<10;i++)
{
console.log(i);
}

Image description

while loop

let i=0;
while(i<10)
{
console.log(i);
i++;
}
Image description

do-while loop

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

Image description

forEach Loop
(used for iterate every value , it is a type of syntactic sugar , to write in a better way)

let arr2=[10,20,30,40];

arr2.forEach(function(element){
console.log(element);
})
Image description

forIn loop
(it is only used to iterate or display content present inside the object)

for(let key in obj)
{
// console.log(key);
// console.log(obj[key]);
console.log(The ${key} of the person is ${obj[key]});
}
Image description

Top comments (0)