Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 818 Bytes

SC2105.md

File metadata and controls

42 lines (30 loc) · 818 Bytes

Pattern: Use of break/continue outside a loop

Issue: -

Description

These statements are only valid in loops. In particular, break is not required in case statements as there is no implicit fall-through.

To return from a function or sourced script, use return. To exit a script, use exit.

Example of incorrect code:

case "$1" in
    -v)
       verbose=1
       break
       ;;
    -d)
       debug=1
esac

Example of correct code:

case "$1" in
    -v)
       verbose=1
       ;;
    -d)
       debug=1
esac

Exceptions

It's possible to break/continue in a function without a loop. The call will then affect the loop -- if any -- that the function is invoked from.

Further Reading