2: // Looping with goto
3:
4: #include <iostream.h>
5:
6: int main()
7: {
8: int counter = 0; // initialize counter
9: loop: counter ++; // top of the loop
10: cout << "counter: " << counter << "\n";
11: if (counter < 5) // test the value
12: goto loop; // jump to the top
13:
14: cout << "Complete. Counter: " << counter << ".\n";
15: return 0;
16: }
Output: counter: 1
counter: 2
counter: 3
counter: 4
counter: 5
Complete. Counter: 5.