package main
import (
"fmt"
"math"
)
func cappedPow(x, n, lim float64) float64 {
// executing a short statement before the
// actual condition occurs. the statement
// values are available on the 'else'
// as well.
if v := math.Pow(x, n); v < lim {
return v
} else {
fmt.Printf("oh noes, %g >= %g!\n", v, lim)
}
return lim
}
func main() {
fmt.Println(cappedPow(3, 2, 10))
fmt.Println(cappedPow(3, 3, 20))
}
To embed this program on your website, copy the following code and paste it into your website's HTML: