Javascript With Loop
Mahin Tazuar
Posted on September 6, 2021
Loop is a very important thing in every programming language. When we need to do something again and again and also need to control the infinite process. At this time we are use Loop.
Today we apply this in Javascript Language. Javascript have 5 kinds of loop.
- for
- for in
- for of
- While
Do while
for loop :
for loop have a simple syntax, as usually, we need to use define some statement after for loop keyword. normally for loop working with array.for in loop working with an object. If we need to get object element then we are using this loop.
Ex:
let dt = [
'mahin','tazuar'
]
for (d of dt){
console.log(d) // mahin ,tazuar
}
- for loop working with an array, It's a simple return array element.
let data = {
name:'mahin',
age:34
}
for (a in data){
console.log(data[a]) // mahin , 34
}
- That is simple and like for loop
- Do while loop, when we need to do something after we are starting our loop in this time we are using do-while loop.
let data = [1,34,343,5345,4656,56]
var i = 0;
do {
console.log(data[i])
i++;
}
while (i < -1);
do while loop , real life example -
suppose your hand is not clean , so you use do loop and wash your hand. then while loop check the hand if the hand is clean execute the while otherwise loop is start agin.
Posted on September 6, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.