> For the complete documentation index, see [llms.txt](https://sphantix-hang.gitbook.io/timebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sphantix-hang.gitbook.io/timebook/3.-yu-yan-pian/golang/dai-ma-gui-fan/unnecessary_else.md).

# 不必要的else

如果在`if`的两个分支中都设置了变量，则可以将其替换为单个`if`。

```go
//bad usage
var a int
if b {
  a = 100
} else {
  a = 10
}

//good usage
a := 10
if b {
  a = 100
}
```
