Exit(n) vs. goto
- Posted by kbochert at ix.netcom.com Feb 17, 2002
- 512 views
-------Phoenix-Boundary-07081998- A personal opinion on the inadvisability of 'exit(n)'. The problem of breaking out of nested loops is real but exit(n) is a bit of a write-only way of handling it. Ask yourself- Is the purpose of exit(N) to break out of N loops, or is it to get to a specific location in the code (which happens to be at the end of a specific loop). A loop that includes an exit(n) statement is making assumptions about the structure of its environment. Finding the target of exit(3) can be difficult, involving the counting, both up and down, of 2 kinds of loops, possibly over several pages of code. You can't even use your editor to do the search! Changing the nesting structure of the code can require fixing exit() statements. The typical use of exit(N) would be when some significant milestone in the processing occured: 'error_found', or 'start_next_step'. 'exit(N)' gives no clue. Goto is more semanticly meaningful, more versatile, runs faster and its target is more easily found. Karl Bochert -------Phoenix-Boundary-07081998---