Repeat code for as long as a condition is true, instead of copying it.

In this video:

  • Adding up numbers the user enters, and why copying the same code again and again bloats a program
  • while (condition) { ... } runs the code in braces again and again while the condition is true
  • Counting the rounds with a variable times, and the condition times > 0
  • --times makes times one smaller in each round; without it the condition stays true and the loop never ends
  • Letting the user choose how many times the loop runs with std::cin >> times;
  • When the condition is false from the start, such as times being 0, the loop doesn't run at all