• Statements

    A condition statement is like a question in programming. It helps the computer decide what to do next. For example, if you go to a store, you might ask the shopkeeper if they have what you want. The shopkeeper will answer yes or no, and that will help you decide what to do next. In programming, the computer can ask itself questions to decide what it should do next.

      • If Statements

      • package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	if x > 0 {
        		fmt.Println("variable x is greater than zero") // variable x is greater than zero
        	}
        }
        
      • Else Statements

      • package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	if x > 0 {
        		fmt.Println("variable x is greater than zero") // variable x is greater than zero
        	} else {
        		fmt.Println("else, variable x is zero or less") // else, variable x is zero or less
        	}
        }
        
      • Else If Statements

      • package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	if x > 0 {
        		fmt.Println("variable x is greater than zero") // variable x is greater than zero
        	} else if x == 0 {
        		fmt.Println("") // else if, variable x is zero
        	}
        }
        
      • Switch Statements

      • package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	var result string
        	switch x {
        	case 0:
        		result = "variable x is integer zero"
        
        	case 1:
        		result = "variable x is integer one"
        
        	default:
        		result = "variable x is anything else"
        	}
        
        	fmt.Println(result) // variable x is integer one
        }