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.
Using functionality from
algorithm header is 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.