For loops loop over something a defined number of times. A while loop is able to run an undefined number of times until a condition is met.
constarray=newArray(10);for(leti=0;i<array.length;i++){// This will always run 10 timesconsole.log(i);};
functionmain(){letstate=false;// This will loop a random number of times until that condition is metwhile(!state){constranNum=generateRandomNumber();if(ranNum===5){state=true;}}};
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Mateusz, I would like to know when the while loops are to be used instead of the for loops. Thanks
For loops loop over something a defined number of times. A while loop is able to run an undefined number of times until a condition is met.