Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Do...while Loop | Introduction to Program Flow
C++ Introduction

Do...while Loop

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 one time when the while loop would never have executed.

Everything was clear?

Section 4. Chapter 5
course content

Course Content

C++ Introduction

Do...while Loop

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 one time when the while loop would never have executed.

Everything was clear?

Section 4. Chapter 5
some-alt