Python has an interesting for
statement which lets you specify an else
clause.
In a construct like this one:
for i in foo:
if bar(i):
break
else:
baz()
the else
clause is executed after the for
, but only if the for
terminates normally (not by a break
).
I wondered if there was an equivalent in C++? Can I use for ... else
?