Shell: Break both if and for loop at once.My script: ip to name resolve codeIP=192.168.27.191hostNameChecker(){    if [ `getent hosts $1 | wc -l` -ne 0 ];then        HOST_NAME=`hostname`        DNS_IP=`getent hosts $1 | cut -d   -f 1 | sed 's/^[ \t]*//;s/[ \t]*$//'`        DNS_NAMES=`getent hosts $1 | cut -d   -f 2- | sed 's/^[ \t]*//;s/[ \t]*$//'`        for DNS_NAME in ${DNS_NAMES[@]}         do            if [[ $DNS_NAME == $HOST_NAME ]];then                    echo Host name:$HOST_NAME and DNS_NAME:$DNS_NAME matched                    break 2;########Not working. only brakes inner for not outer if                 else                    continue;                fi        done            echo ERROR: Mismatch between DNS:$DNS_NAMES and Hostname:$HOST_NAME            exit 0      fi}hostNameChecker $IPIn the above script break 2 only breaks inner for not outer if. I can add another if to solve it but is there any other possible way ???
Shell: Break both if and for loop at once
shell;shell script;control flow
break has no effect on if statements.  In your use case, return will have the effect you're seeking, since there are no statements after the outer if, and return exits the function.