1. // echoWhile.cpp
 2. // Echoes lines of text typed by the user,
 3. // until the user types Ctrl-C to quit.
 4. //
 5. // Run this program and understand how it works.
 6. // Then re-write as equivalent nested for loops.
 7. //
 8. // In the heading of the inner loop,
 9. // '\n' is the newline character, used as
10. // end-of-line marker on Unix systems.
11. // (On Windows systems, the end-of-line
12. // marker would consist of a carriage
13. // return, '\r', followed by newline.)
14. 
15. #include <iostream>
16. using namespace std;
17. 
18. int main()
19. {
20. 
21.    cout << "Type a few lines of text, "
22.            << "then Ctrl-C to quit:" << endl;
23. 
24.    char letter;
25.    cin.get(letter);
26.    while ( true )
27.    {
28.       cout << "You tuped: ";
29. 
30.       while ( letter != '\n' )    // '\n' is end-of-line on Unix
31.       {
32.          cout << letter;
33.          cin.get(letter);
34.       }  // while
35. 
36.       cout << endl;
37.       cout << "Type another line (or Ctrl-C to quit):" << endl;
38.       cin.get(letter);
39.    }  // while
40. }  // function main