Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sugilog
Created December 28, 2014 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugilog/a035c78979c1a04659a9 to your computer and use it in GitHub Desktop.
Save sugilog/a035c78979c1a04659a9 to your computer and use it in GitHub Desktop.
条件分岐:if
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