I have a range-based for that operates over a std::vector
of objects (item
s), like so:
for(auto item : itemCollection)
{
if(!item.some_check(...))
{
// do 5% stuff
break;
}
// do the 95% stuff
}
Most of the time (>95%) the loop operates on the entire container, however, if some_check()
returns a false
(about 5% of the time), it'll break out of the loop early.
Is it considered bad form to break out of a range-based for? Should I instead use a while
or a C++03-style for(...;...;...)
here?