+ 1

Can someone explain what are the meanings and differences of for(), while(), and do-while() loops?? Thank you in advance

10th Dec 2020, 11:35 AM
Joyce
Joyce - avatar
4 Answers
+ 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
10th Dec 2020, 12:20 PM
Moniruzzaman Saikat
Moniruzzaman Saikat - avatar
+ 1
Thankyouu!!❀ BeegCat
10th Dec 2020, 12:39 PM
Joyce
Joyce - avatar
0
Thank youuu!!❀ Moniruzzaman Saikat
10th Dec 2020, 12:41 PM
Joyce
Joyce - avatar