What are the differences between a while loop and a for loop? It seems to me that they are the same.
What are the differences between a while loop and a for loop?
loops
The while loop is usually used when you need to repeat something until a given condition is true:inputInvalid = true;while(inputInvalid){    //ask user for input    invalidInput = checkValidInput();}On the other hand, the for loop is usually used when you need to iterate a given number of times:for(var i = 0; i < 100; i++){    ...//do something for a 100 times.}You can use them interchangeably if you like:inputInvalid = true;for(;;){    if(!inputInvalid)    {        break;    }    //ask user for input    invalidInput = checkValidInput();}OrinputInvalid = true;for(;inputInvalid;){            //ask user for input    invalidInput = checkValidInput();}And:var i = 0;while(i < 100){    //do your logic here    i++;}