Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

The do/while loop


The do/while loop is almost identical to the while loop. Here's an example of a do/while loop that is equivalent to the first while loop that we examined:

int x = 1;
do
{
  cout << "x is " << x << endl;
  x++;
} while( x <= 5 ); // may only loop back when x<=5
cout << "End of program" << endl;

The only difference here is that we don't have to check the while condition on our first entry into the loop. This means that the do/while loop's body is always executed at least once (where a while loop can be skipped entirely if the condition to enter the while loop is false when you hit it for the first time).