"Go goto"의 두 판 사이의 차이

37번째 줄: 37번째 줄:


==참고==
==참고==
* https://golang.org/src/math/gamma.go
* https://go.dev/ref/spec#Goto_statements
* https://pyrasis.com/book/GoForTheReallyImpatient/Unit18


[[분류: Go]]
[[분류: Go]]

2023년 5월 4일 (목) 00:55 판

1 개요

Go goto
  • 꼭 필요한 경우가 아니라면, 이것 대신 for, if, switch, func로 구현하는 것이 좋다.
  • 암튼 있으니까 놀아보자. ㅎ
package main
import "fmt"
func main() {
    goto world
    fmt.Println("hello")
world:
    fmt.Println("world")
}
package main
import "fmt"
func main() {
    sum := 0
    i := 1
myloop:
    if i > 10 {
        goto mydone
    }
    sum += i
    i++
    goto myloop
mydone:
    fmt.Println(sum)
}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}