Created
December 28, 2014 15:03
-
-
Save sugilog/a035c78979c1a04659a9 to your computer and use it in GitHub Desktop.
条件分岐:if
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
patternA() | |
patternB() | |
// patternC() | |
} | |
const THRESHOLD = 30 | |
func patternA() { | |
i := time.Now().Second() | |
if i > THRESHOLD { | |
fmt.Println( "more than", THRESHOLD ) | |
} else { | |
fmt.Println( "less than or equal to", THRESHOLD ) | |
} | |
fmt.Println( "value:", i ) | |
} | |
func patternB() { | |
threshold1 := THRESHOLD + 10 | |
threshold2 := THRESHOLD - 10 | |
if i := time.Now().Second(); i > threshold1 { | |
fmt.Println( "more than", threshold1 ) | |
} else if i > threshold2 { | |
fmt.Println( "more than", threshold2 ) | |
} else { | |
fmt.Println( "less", threshold1, threshold2 ) | |
} | |
// fmt.Println( "value:", i ) | |
} | |
// func patternC() { | |
// i := time.Now().Second() | |
// if i > THRESHOLD { | |
// message := fmt.Sprintf( "more than %d", THRESHOLD ) | |
// } else { | |
// message := fmt.Sprintf( "less than or equal to %d", THRESHOLD ) | |
// } | |
// fmt.Println( message ) | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment