What is the difference between FOR and WHILE loop ?

what is the difference between for and while loop ???

A while loop works like this

while ( <condition> )  // while the condition is true, the while loop continues
{
    //  code
}

A for loop is

for( <initialization> ; <condition> ; <increment/decrement>)    
// while the condition is true, the for loop continues
{
    // code
}

Actually, the implementation of a for loop is

<initialization>
while ( <condition> )
{
    //  code
    <increment/decrement>
}
1 Like

Well, for loop is generally used when the number of iterations are known but while loop is generally used when the number of iterations are unknown.

I think you know the syntaxx of for and while loop. Well it is indeed known that while loop is slower than for loop… That is the best difference you need to know… You can implement any loop any where elsewise(Forgetting about the ease)