Programming/golang2024. 2. 8. 11:26

어우.. 키워드 긴것 보소 -_-

 

fallthrough 하면 c에서 break 없이 case를 붙이면 조건 비교는 없이 다음 case를 실행했었는데

golang 에서도 조건을 보진 않고 그냥 다음 문장을 수행한다.

다만 가장 마지막 case에는 당연히(?) fallthrough를 넣으면 에러가 발생한다.

package main

import "fmt"

func main() {
    i := 45
    switch {
    case i < 10:
        fmt.Println("i is less than 10")
        fallthrough
    case i < 50:
        fmt.Println("i is less than 50")
        fallthrough
    case i < 100:
        fmt.Println("i is less than 100")
    }
}

 

Output

i is less than 50
i is less than 100

[링크 : https://golangbyexample.com/fallthrough-keyword-golang/]

[링크 : https://pyrasis.com/book/GoForTheReallyImpatient/Unit19/02]

'Programming > golang' 카테고리의 다른 글

golang echo 템플릿 파일로 불러오기  (0) 2024.02.14
golang switch  (0) 2024.02.08
golang break, continue 라벨 그리고 goto  (0) 2024.02.08
golang import  (0) 2024.02.07
golang iota  (0) 2024.02.07
Posted by 구차니