Skip to content

Instantly share code, notes, and snippets.

@tsuyukimakoto
Created July 2, 2022 10:29
Show Gist options
  • Save tsuyukimakoto/ad793d9da840693e678454543e418473 to your computer and use it in GitHub Desktop.
Save tsuyukimakoto/ad793d9da840693e678454543e418473 to your computer and use it in GitHub Desktop.
scopeを狭くできるif
package main
import "fmt"
func a() (x string, y bool) {
return "test", true
}
func main() {
if _, y := a(); y {
fmt.Println("true: ", y)
} else {
fmt.Println("false", y)
}
// fmt.Println("result: ", y) <- out of scope
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment