answersLogoWhite

0

The while loop is the more general one because its loop condition is more flexible and can be more complicated than that of a for loop. The condition of a for loop is always the same and implicit in the construction. A for loop stops if there are no more elements in the collection to treat. For simple traversals or iterations over index ranges it is a good advice to use the for statement because it handles the iteration variable for you, so it is more secure than while where you have to handle the end of the iteration and the change of the iteration variable by yourself.

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan

Add your answer:

Earn +20 pts
Q: Compare While with for Statements
Write your answer...
Submit
Still have questions?
magnify glass
imp