diff --git a/1flow/for.go b/1flow/for.go new file mode 100644 index 0000000..8b655f7 --- /dev/null +++ b/1flow/for.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("There is no parantheses in for loop unlike other languages") + fmt.Println("braces are necessary in for loop") + + /* SYNTAX: + for INIT; CONDITION; POST { + + } + */ + + sum := 0 + for i := 0; i < 10; i++ { + sum += i + } + fmt.Println(sum) + + fmt.Println("Init and post statements are optional\nSo you can use for loop as while in other languages") + + val := 100 + for val > 0 { + val -= 1 + } + fmt.Println(val) + + fmt.Println("break and continue keywords are same as C") + +} diff --git a/1flow/if.go b/1flow/if.go new file mode 100644 index 0000000..166294d --- /dev/null +++ b/1flow/if.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("No parantheses, braces required") + val := 1 + if val == 0 { + fmt.Println("1") + } else if val == 1 { + fmt.Println("2") + } else { + fmt.Println("3") + } + + fmt.Println("Also you can execute short statement before condition") + if val2 := 1; val2 > 0 { + fmt.Println(val2) + } + // fmt.Println(val2) // ERROR, out of scope + +}