Python has an interesting for
statement which lets you specify an else
clause.
In a construct like this one:
for i in foo:
if
It's not only possible in C++, it's possible in C. I'll stick with C++ to make the code comprehensible though:
for (i=foo.first(); i != NULL || (baz(),0); i = i.next())
{
if bar(i):
break;
}
I doubt I'd let that through a code review, but it works and it's efficient. To my mind it's also clearer than some of the other suggestions.