1. What is difference between For loop and While loop ?
The
On the other hand, the
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.
}