Go 언어 조건문 대하여 배워보기
Go 언어 조건문 대하여 배워보기
오늘은 Go 언어의 조건문에 대하여 작성하면서 배워보려 합니다.
if else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package main
import (
"fmt"
)
func main() {
example := "hello, world!"
if example == "hello, world!" {
fmt.Println("hello")
} else{
fmt.Println("hello")
}
}
기본적으로 조건문은 위와 같이 사용합니다.
statement
1
2
3
4
5
6
7
8
9
10
11
12
13
package main
import (
"fmt"
)
func main() {
if temp := 3.14; temp > 3 {
fmt.Println("true!")
}else{
fmt.Println("false")
}
}
짧은 수행문을 if에 포함할 수 있습니다.
조건문과는 세미클론으로 구별합니다.
else if
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package main
import (
"fmt"
)
func main() {
if temp2 := 3.14; temp2 < 3 {
fmt.Println("true!")
}else if temp2 == 3.14{
fmt.Println("pi!")
}else{
fmt.Println("false")
}
}
else if는 위와 같이 사용합니다.
This post is licensed under CC BY 4.0 by the author.