Computer Science, asked by saikireeti403, 1 year ago

When do we choose for loop? How is it different from a while loop?

Answers

Answered by AneesAhmed
13
For loop, means when a stated condition has to be true then it go on repeats for looping until the condition is satisfied and then exits the loop. where as while loop ensures to see only if the condition is true then it'll executes the code to display or something or else if it is false then throws compile time error and proceeds further. that's all
Answered by lovingheart
6

We go for looping statement whenever we want to repeat certain number of lines with a specific condition. There many kinds of loop such as for-loop, while loop and do-while loop.  

A while loop is expected to be used when the number of times that the loop should be executed is not aware and it would be decided base on how the loop runs, then go for while loop. The main difference between while loop and for loop is that, while loop splits the initialization, condition and increment/ decrement statements.

Similar questions