Next: Example while loop: Summing Up: The while statement Previous: The while statement


Example while loop: Printing integers

The following while statement prints out the numbers 1 to 10, each on a new line.

int i;
i = 1;
while (i <= 10)
  {
    cout << i << endl;
    i++;
  }
Download program.



Next: Example while loop: Summing Up: The while statement Previous: The while statement