bool next(Type& arg) { if (...) { return false; } else { arg = ...; return true; } } while (i->next(arg)) { ... }