a0be824b595f603a51a3d75b98231946d1ee2be7 — kotrunga 8 months ago f66a1e8
Add second if example
1 files changed, 27 insertions(+), 0 deletions(-)

A basics/flow-control-statements/1.2.6_if-with-a-short-statement.go
A basics/flow-control-statements/1.2.6_if-with-a-short-statement.go => basics/flow-control-statements/1.2.6_if-with-a-short-statement.go +27 -0
@@ 0,0 1,27 @@
+ /*
+ 	Notes 1.2.6
+ 
+ 	- Just like 'for', 'if' can start with a short statement to execute before the condition
+ 	- Any variables declared in this statement are out of scope at the end of the 'if'
+ */
+ 
+ package main
+ 
+ import (
+ 	"fmt"
+ 	"math"
+ )
+ 
+ func pow(x, n, lim float64) float64 {
+ 	if v:= math.Pow(x, n); v < lim {
+ 		return v
+ 	}
+ 	return lim
+ }
+ 
+ func main() {
+ 	fmt.Println(
+ 		pow(3, 2, 10),
+ 		pow(3, 3, 20),
+ 	)
+ }< 
\ No newline at end of file