Source file tour/flowcontrol/if-and-else.go

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"math"
     8  )
     9  
    10  func pow(x, n, lim float64) float64 {
    11  	if v := math.Pow(x, n); v < lim {
    12  		return v
    13  	} else {
    14  		fmt.Printf("%g >= %g\n", v, lim)
    15  	}
    16  	// can't use v here, though
    17  	return lim
    18  }
    19  
    20  func main() {
    21  	fmt.Println(
    22  		pow(3, 2, 10),
    23  		pow(3, 3, 20),
    24  	)
    25  }
    26  

View as plain text