+ 3

What is the difference between while loop and for loop?

4th Jun 2017, 10:20 AM
DarkVortex
DarkVortex - avatar
4 Answers
+ 8
I would like to say "no difference" bc infinite loop: while(true){cout << "Ahem";} for(;true;){cout << "Ahem";} Both of them will show result as infinite loop More: Those code can be shorten with while(1){cout << "Moo ";} for(;;){cout << "M0o ";}
4th Jun 2017, 10:25 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 6
The difference isn't in the loop, but in the use for the loop. generally a while loop is run until a condition is met whereas a for loop is usually run a set amount of times
4th Jun 2017, 11:37 AM
LordHill
LordHill - avatar
+ 3
@justin thank you 😊 now i got it
4th Jun 2017, 12:34 PM
DarkVortex
DarkVortex - avatar
+ 2
thank you 😊
4th Jun 2017, 10:25 AM
DarkVortex
DarkVortex - avatar