Whats the use of while-loop

In what kind of problem can I use while-loop?

1
2
3
4
5
int a;
while ( cin >> a ) 
{
  cout << a;
}
how do you get out of that while loop?
Enter an EOF character on the keyboard (ctrl-C on windows).

while loops are best suited for a section of code that you want to execute while some condition is true. This is in contrast to a for loop which is usually used when you want to execute the loop a fixed number of times.

enter non-int: http://ideone.com/kpVwCc
AbstractionAnon wrote:
Enter an EOF character on the keyboard (ctrl-C on windows).
It's Ctrl+Z, because Ctrl+C is to break/terminate the program.
Topic archived. No new replies allowed.