Download c++ eBook


A loop statement executes a group of statements repeatedly until a condition is met. There are 3 types of primitive loops in C++: for, while, and do...while.


  • while (condition) statement ;
  • do statement while (expression) ;
  • for (for-init-statement ; condition ; expression) statement ;
  • for (for-range-declaration : for-range-initializer) statement ;
  • break ;
  • continue ;


algorithm calls are generally preferable to hand-written loops.

If you want something an algorithm already does (or something very similar), the algorithm call is clearer, often more efficient and less error prone.

If you need a loop that does something fairly simple (but would require a confusing tangle of binders and adapters if you were using an algorithm), then just write the loop.

Related Examples


794 Contributors: 30
Sunday, July 9, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook