go9 조건문 if 조건문 보통 알고 있는 if문의 문법과 거의 동일하다. if 조건 { } 의 형식이다. if else 형식도 기존의 다른 언어 들과 동일하다. 다만 조건문의 Scope는 python과는 다르게 Brace로 구별한다. else if 문도 지원한다. c++, java, javascript라 다른 점은 조건을 쓸때 괄호로 감싸지 않는다. package main import ( "fmt" "math/rand" ) func main() { randNumber := rand.Intn(20) if randNumber > 10 { fmt.Println("this number over 10") } else if randNumber > 5 { fmt.Println("this number over 5") } else { f.. 2020. 12. 18. 반복문 GO lang에서의 반복문 특별히 설명할 것이 많이 없다. 단순하게 for문 하나뿐이 없다. 다만, For문하지 지만, 다양한 형태를 제공해 주기 때문에 특별하게 다른 예약어는 없이 그냥 for문하나로 통일해 버렷다. 일반적인 For문 for i := 0; i < 10; i++ { sum += i } while 문 형태 sum := 1 for sum < 1000 { sum += sum } foreach문 형태 아직 배열 초기화나 배열에 대해서 살펴 본것이 아니기 때문에 그냥 형태만 살펴 보면 된다. animals := []string{"dog", "cat", "hedgehog"} for _, animal := range animals { fmt.Println("My animal is:", animal) .. 2020. 12. 14. Go lang 기본 문법 1 GO 기본 문법 이번에는 아주 기본이 되는 go에 문법에 대해서 알아 보겠다. package main import "fmt" func main() { fmt.Println("This is Main function") } 위와 같이 코드를 작성한 후 main.go라는 이름으로 저장한다. powershell이나 cmd창을 열고, `go run ./main.go` 라고 입력한다. 화면에 아래와 같이 This is Main function 이라는 글자가 찍히는 것을 확인 할 수 있다. A Tour of Go (golang.org): 여기에 나오는 문제들을 하나 하나 따라 하다 보면 기본적인 문법은 알수 있다. package main // 현재 이 파일이 속한 package의 이름 import "fmt" // 모.. 2020. 12. 8. GO lang 설치와 실행 Go lang 설치 Download and install - The Go Programming Language (golang.org) Download and install - The Go Programming Language Download and install Download and install Go quickly with the steps described here. For other content on installing, you might be interested in: 1. Go download. Click the button below to download the Go installer. Download Go Don't see your operating syste golang.org 공식 홈.. 2020. 12. 2. 이전 1 2 3 다음