course content

Course Content

Introduction to C++

do...whiledo...while

Unlike a while loop, which may never execute, a do...while loop is guaranteed to execute at least once.

Structure of do…while loop:

Note

The line containing the while part ends with a semicolon (;)

Now let's compare the while and do…while loops.

The while loop:

cpp

main.cpp

The do...while loop:

cpp

main.cpp

The do...while loop executed 1 time when the while loop would never have executed.

Section 4.

Chapter 5