while & do-while loops

This lesson introduces the while and do-while loops in C++. It uses coding examples to show their implementation and explain their workings.

Loops allow a programmer to execute the same block of code repeatedly. We will make heavy use of conditional statements in this section.

The while Loop

The while loop is really the only necessary repetition construct. The for loop, coming up, can be duplicated using a while loop, and with more control. A simple negation can perform the same behavior as do-while loop.

The syntax is as follows:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy