+ 4
Difference between 'for' and 'while' in C++?
I've done the courses on these, but I don't understand the difference. It seems like you can put as many things into 'while' as many you want, while in 'for', only one?
3 Answers
+ 7
The fun is. There is no difference. Both are loops.
You can rewrite almost every for-loop to a while-loop and the other way around.
https://code.sololearn.com/cd6jKsP0ZWY4
Ok
generally speaking.
You choose a for-loop, when you know how many iterations you need to do
You choose a while-loop when the number of iterations can differ based on user input.
The one while-loop you cannot rewrite to a for-loop is.
While (next user input is "x"){}
+ 3
You can do as many things in a for loop as well.