585c8aabd9b36e77489df2d1236ed848022baf41 — coltonhurst 9 months ago ac346fc
for loops and started if statements
A basics/flow-control-statements/1.2.1_for.go => basics/flow-control-statements/1.2.1_for.go +23 -0
@@ 0,0 1,23 @@
+ /*
+ 	Notes 1.2.1
+ 
+ 	- Go only has one looping construct- the for loop!
+ 	- There are three components separated by semicolons:
+ 	  - the init statement
+ 	  - condition expression
+ 	  - post statement
+ 	- There are no parenthesis around the 3 components in the "loop header" (what I'm calling it)
+ 	- Braces on a loop { } are always required
+ */
+ 
+ package main
+ 
+ import "fmt"
+ 
+ func main() {
+ 	sum := 0
+ 	for i := 0; i < 10; i++ {
+ 		sum += i
+ 	}
+ 	fmt.Println(sum)
+ }< 
\ No newline at end of file

A basics/flow-control-statements/1.2.2_for-continued.go => basics/flow-control-statements/1.2.2_for-continued.go +17 -0
@@ 0,0 1,17 @@
+ /*
+ 	Notes 1.2.2
+ 
+ 	- The init and post statements are optional (condition is necessary)
+ */
+ 
+ package main
+ 
+ import "fmt"
+ 
+ func main() {
+ 	sum := 1
+ 	for ; sum < 1000; {
+ 		sum += sum
+ 	}
+ 	fmt.Println(sum)
+ }< 
\ No newline at end of file

A basics/flow-control-statements/1.2.3_for-is-gos-while.go => basics/flow-control-statements/1.2.3_for-is-gos-while.go +18 -0
@@ 0,0 1,18 @@
+ /*
+ 	Notes 1.2.3
+ 
+ 	- Well, you don't even need the semicolons!
+ 	  If you just have a condition, it's just like a C while loop
+ */
+ 
+ package main
+ 
+ import "fmt"
+ 
+ func main() {
+ 	sum := 1
+ 	for sum < 1000 {
+ 		sum += sum
+ 	}
+ 	fmt.Println(sum)
+ }< 
\ No newline at end of file

A basics/flow-control-statements/1.2.4_forever.go => basics/flow-control-statements/1.2.4_forever.go +13 -0
@@ 0,0 1,13 @@
+ /*
+ 	Notes 1.2.4
+ 
+ 	This is an infinite loop. You probably don't want this.
+ */
+ 
+ package main
+ 
+ func main() {
+ 	for {
+ 		
+ 	}
+ }< 
\ No newline at end of file

A basics/flow-control-statements/1.2.5_if => basics/flow-control-statements/1.2.5_if +0 -0

A basics/flow-control-statements/1.2.5_if.go => basics/flow-control-statements/1.2.5_if.go +23 -0
@@ 0,0 1,23 @@
+ /*
+ 	Notes 1.2.5
+ 
+ 	- if statements in Go are like the for loops. No parenthesis necessary, but { } required
+ */
+ 
+ package main
+ 
+ import (
+ 	"fmt"
+ 	"math"
+ )
+ 
+ func sqrt(x float64) string {
+ 	if x < 0 {
+ 		return sqrt(-x) + "i"
+ 	}
+ 	return fmt.Sprint(math.Sqrt(x))
+ }
+ 
+ func main() {
+ 	fmt.Println(sqrt(2), sqrt(-4))
+ }< 
\ No newline at end of file