While and Do-While Loops

Learn about the while and the do-while loop constructs in C++.

Several programming tasks consist of executing the same code multiple times. Tasks like moving an object across the screen, iterating through a list of items, searching through data, and performing mathematical operations on a stream of numbers; all consist of a block of code being executed repeatedly till a termination condition is met. C++ allows executing the same code several times using two different loop constructs:

  • The while loop and its variation the do-while loop

  • The for loop

The while Loop

The while loop is really the only necessary repetition construct. The for loop and the do - while loop, coming up shortly, can be replicated using a while loop.

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

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