a39813859005296ba5567148c66928118484fb1f — kotrunga 8 months ago a0be824
Add if and else example
1 files changed, 29 insertions(+), 0 deletions(-)

A basics/flow-control-statements/1.2.7_if-and-else.go
A basics/flow-control-statements/1.2.7_if-and-else.go => basics/flow-control-statements/1.2.7_if-and-else.go +29 -0
@@ 0,0 1,29 @@
+ /*
+ 	Notes 1.2.7
+ 
+ 	- Variables declared in the 'if' short statement are available in the 'else' blocks
+ */
+ 
+ package main
+ 
+ import (
+ 	"fmt"
+ 	"math"
+ )
+ 
+ func pow(x, n, lim float64) float64 {
+ 	if v:= math.Pow(x, n); v < lim {
+ 		return v
+ 	} else {
+ 		fmt.Printf("%g >= %g\n", v, lim)
+ 	}
+ 	// can't use v here, though
+ 	return lim
+ }
+ 
+ func main() {
+ 	fmt.Println(
+ 		pow(3, 2, 10),
+ 		pow(3, 3, 20),
+ 	)
+ }< 
\ No newline at end of file