IF FOR SWITCH

/* IF YOU GET ANY ERRORS IN THE PROGRAM CHECK THE POSITION OF "{" ALWAYS*/


PROGRAM 1
/* Program showing if looping */

package main

import "fmt"

func main() {
var a int = 5
fmt.Print("This is an Example and working of \"if\" control in go\n")

if a == 5 {
fmt.Print("program entered \"if\" loop\na value is ",a)
}
fmt.Print("\nProgram exit line outside \"if\"\n")
}

PROGRAM 2
/* Program showing if-else control */
package main
import "fmt"
func main() {
var a int = 5
fmt.Print("This is an example for working of \"if-else\" control\n")
if a == 5 {
fmt.Print("Program Entered \"if\" loop\nand wont enter while\n")
} else { 
fmt.Print("This is part of the control flow\n and program didnt enter \"if\"\n")
}
}


FOR:
/*NOTE: Go has eliminated all the remaining looping such as while,do-while etc and retained only FOR loop. using for loop all the remaining loops can be created.


PROGRAM 3:
package main
import "fmt"
func main() { 
var i int
fmt.Print("This is an example for working of \"for\" loop\n")
for i=0 ; i <= 5 ; i++ {
fmt.Print(i,"\n")
}
}
PROGRAM 4:
/*Demonstration of while loop using for*/
package main

import "fmt" 

func main() {
fmt.Print("This program shows for loop with 1 exp\nand use of for as while\n")
var i int = 0 
for <= 10 {
fmt.Print(i,"\n")
i++
}
}
SWITCH:
/*Switch is much more powerful in "GO" compared to "C"
There are two types one familiar form which is of the type used in c
Second in which test expression is missing meaning its always true resulting in if-else chain.*/


PROGRAM 5:
/*This is of first type*/


package main
import "fmt"
func main() {
fmt.Print("This program is an example for ordinary \"C and C++\" type of switch statement\n")
var a = 1
switch a {
case 1:
fmt.Print("Case value 1\n"); fallthrough;
case 2:
fmt.Print("Case value 2\n")
case 3:
fmt.Print("Case value 3\n")
}
}


PROGRAM 6:
/*This is the second type*/
package main  
import "fmt"  
func main(){
fmt.Print("This is an example for complex \n Non \"C and C++\" type of switch usage\n")
a,b:=2,3
switch {
case a < b:
fmt.Print("a is less than b\n")
case a > b:
fmt.Print("a is greater than b\n")
case a == b:
fmt.Print("a is equal to b\n")
}
}


PROGRAM 7:
/*This is a switch which executes false statement. First false statement will be executed*/


package main
import "fmt"
func main() {
fmt.Print("This is a switch program with false case\n")
var a = 1
var b = 1
switch false {
case a == b:
fmt.Print("a is equal to b\n")
case a < b:
fmt.Print("a is less than b\n")
case a > b:
fmt.Print("a is greater than b\n")
}
}