The checkNumbers function
Now that we have looked at the different parts of the function, let’s see how these parts work with various examples. Let’s start with a simple approach with a checkNumbers function. The checkNumbers function prints out various messages based on some math results of whether a number is even or odd. The rules perform one of the actions based on the number given:
- If the number is even, printEven
- If the number is odd, printOdd
The following is the code snippet to achieve this output:
func checkNumbers() {
    for i := 1; i <= 30; i++ {
        if i%2 == 0 {
            fmt.Println("Even")
        } else {
            fmt.Println("Odd")
        ... 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                