3 ms·
I had an instructor once that insisted on having a single exit point for all loops. "Never use break or continue or return from a loop." The argument was that u
by Retra 10y ago
I had an instructor once that insisted on having a single exit point for all loops. "Never use break or continue or return from a loop." The argument was that understanding control flow is more complex when you don't have to deal with these things.
However, those things exist in the language. You can't just pretend nobody is going to use them, because there might be very good reasons to use them, especially in an imperative context.
(Though I suppose if you're grading 100 projects, such a rule might make it easier to get the code structured the same everywhere.)
- kazinator 10y agoIn the world outside of that instructor's classroom, there are coding conventions which forbid certain things, with excellent reasons for doing so. Back when ISO C++ was still staffed by people with useful ideas, they invented various more specialized, safer casts that refuse to do "off topic" conversions. These replace the "(type) expr" C casting notation. A C++ coding convention document can cheerfully forbid C style casts; there isn't any reason to use them.