Check to see if statement is true in the middle of a Do-While statement?

Is there a way to make a code check if the While statement is true while it's going through a list of Do's? And if it's false, it'll stop running the Do's at that point?

I don't want taxes to be paid or the dude to take any fruits if the user has 1 left. So I wanted to add a check between the first cout and the fruits -= 1 so that the guy doesn't try to take a fruit when I have one left after taxes

1
2
3
4
5
6
7
8
do {
            variable++;
            checkpoints -= 1;
            fruits = ceil( fruits / 2 );
            cout << "\nAfter paying taxes " << variable << " times, you will have " << fruits << " fruits.";
            fruits -= 1;
            cout << "\nAfter the dude takes one, you will have " << fruits << " fruits.";
        } while ( checkpoints >= 1 && fruits > 1 );
1
2
if (fruits <= 1)
     break;
Last edited on
Thanks! I didn't think about nesting an if statement in a do-while statement.
Topic archived. No new replies allowed.