不必要的else
如果在if
的两个分支中都设置了变量,则可以将其替换为单个if
。
//bad usage
var a int
if b {
a = 100
} else {
a = 10
}
//good usage
a := 10
if b {
a = 100
}
Last updated
Was this helpful?
如果在if
的两个分支中都设置了变量,则可以将其替换为单个if
。
//bad usage
var a int
if b {
a = 100
} else {
a = 10
}
//good usage
a := 10
if b {
a = 100
}
Last updated
Was this helpful?