同福

代码编写好习惯——避免多层嵌套

一种成功,多种失败

错误的示范

if(cond1){
    if(cond2){
        if(cond3){
            goto success
        }
        else fail3
    }
    else fail2
}
else fail1

正确的示范

if(!cond1){
    goto fail1
}
if(!cond2){
    goto fail1
}
if(!cond3){
    goto fail1
}
goto success

多种成功,一种失败

正确的示范

if(cond1){
    goto success1
}
if(cond1){
    goto success2
}
if(cond1){
    goto success3
}
goto fail

多种成功,多种失败

正确的示范

if(!auth(user, pwd)){
    goto loginFail
}
if(isAdmin){
    goto adminLogin
}
if(!isEnabled){
    goto loginFail2
}
goto userLogin