Archived

This topic is now archived and is closed to further replies.

Do - While loop

This topic is 6034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making a game using Turbo C++ 3.0 DOS and i''m just wondering if there is any possible way i can run a function only ONCE inside a Do-While loop because i''m trying to use cleardevice(); only once in the do while loop. I''ve tried many things and i even tried bools but even if i am able to stop the function later in the do while loop, the do while loop will run again, which means the cleardevice(); will run and stop, run and stop, infinite times.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
bool first_run = true;

do {
if (first_run) {
cleardevice();
first_run = false;
}

/* body code */
} while (/* condition */);

The above will work or just pull the first iteration of your do-while loop out of the body of the do-while loop. So instead of looking like:

do {
/* body code */
} while (/* condition */);

It will look like:

cleardevice();
/* body code */

do {
/* body code */
} while (/* possibly modified condition */);

You may have to modify the condition expression if you do this but.. it''ll work.

Share this post


Link to post
Share on other sites