I have a for loop that iterates through a vector of objects. If an object doesn't meet a condition, I would like to reiterate the same object through the loop until it meets the condition.
int TrainDog(const vector<Dog> &dogs, const Cat big_cat) {
for (auto const dog : dogs) {
dog->Sit(); // tell the dog to sit
if (!dog->IsBarking()) // if dog isn't barking
dog->Eat(raw_burger); // then reward dog
else { // else
dog->PlayWith(big_cat); // punish dog
??? // and train again ???
big_cat++; // with bigger cat
}
}
}
I would prefer to keep this clean iterator instead of using the traditional index variable syntax.