+ 1
Can someone explain what are the meanings and differences of for(), while(), and do-while() loops?? Thank you in advance
3 ответов
+ 1
They all are loops.
for() is one of the most useful thing in programming...
for(initial val; condition; step){
// do something
}
Above, initial val means where to start for a task. Condition means how long your code should repeat. In step, you can jump, you can jump one or two or anything.
Take a look:
for(let i=0; i<5; i = i+1){
console.log(i)
}
It will print 0 through 4. Why not 5 🙃? Because in the condition we said while i is less than 5 run this. If i is bigger than 5 it will exit.
__in while loop you have to init before loop definition, take a look:
let i = 0;
while(i < 5){
console.log(i);
i++;
}
increment the value of i otherwise it will be an Infinity
+ 1
Thankyouu!!❤ BeegCat
0
Thank youuu!!❤ Moniruzzaman Saikat