2: // Looping with while
3:
4:  #include <iostream.h>
5:
6: int main()
7: {
8: int counter = 0; // initialize the condition
9:
10: while(counter < 5) // test condition still true
11: {
12: counter++; // body of the loop
13: cout << "counter: " << counter << "\n";
14: }
15:
16: cout << "Complete. Counter: " << counter << ".\n";
17: return 0;
18: }
Output: counter: 1
counter: 2
counter: 3
counter: 4
counter: 5
Complete. Counter: 5.