+ 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?

13th Apr 2019, 8:31 PM
Kovács Aurél Márk
Kovács Aurél Márk - avatar
3 Réponses
+ 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"){}
13th Apr 2019, 9:01 PM
sneeze
sneeze - avatar
13th Apr 2019, 8:51 PM
Izaak GOLDSTEIN
Izaak GOLDSTEIN - avatar
+ 3
You can do as many things in a for loop as well.
14th Apr 2019, 1:07 AM
Sonic
Sonic - avatar