Quick actions

cmd+k|ctrl+k

Navigation

Languages

if, switch, goto / if statement / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-08-24T16:01:14Z

Updated

2019-08-24T16:01:14Z

package main

import "fmt"

func returnValues(ok bool) (int, bool) {
	return 5, ok
}

func main() {
	if n, ok := returnValues(true); ok {
		fmt.Print("ok is true, n: %d\n", n)
	} else {
		fmt.Print("ok is false, n: %d\n", n)
	}

	// n is only visible within if statement, so this fails compilation
	fmt.Printf("n: %d\n", n)
}
INFO