[Cs3] early algorithm termination

Mikhail Nesterenko mikhail at cs.kent.edu
Sun Feb 25 11:57:41 EST 2024


CS3 students,

There was a discussion in last lecture about termination out of
algorithms like find() on some condition. The advice is to use find_if
which is considered "early termination" in the sense that as soon as
the callback returns true the loop terminates. As I mentioned, it is
possible to get out of the algorithm with an exception. However this
is considered a bad idea as it breaks the program flow.

Any other early exit hacks are discouraged as this obscures the code
and writing an explicit hand written loop is recommended instead.

Thanks,
-- 
Mikhail


More information about the cs3 mailing list