What is a for loop? It is a loop used when the number of iterations are known. A while loop is used when the number of iterations are unknown. This is the main difference between the two loops. Another big difference is that with for loops, initialization happens inside or outside of the loop but a while loop initialization only happens in the loop. And finally, with for loops, if the condition is not stated in the for loop, the loop will iterate an infinite number of times. In a while loop, a complication error will result if the condition is not stated in the loop.
For Loop While Loop
Leave a Reply
You must be logged in to post a comment.