Go fallthrough

1 개요[ | ]

Go fallthrough

2 예제 1[ | ]

package main

import "fmt"

func main() {
	printDigitInfo(3)
	printDigitInfo(2)
	printDigitInfo(1)
}

func printDigitInfo(num int) {
	switch num {
	case 3:
		fmt.Println(num, "≥ 3")
	case 2:
		fmt.Println(num, "≥ 2")
	default:
		fmt.Println(num, "≥ 1")
	}
}
package main

import "fmt"

func main() {
	printDigitInfo(3)
	printDigitInfo(2)
	printDigitInfo(1)
}

func printDigitInfo(num int) {
	switch num {
	case 3:
		fmt.Println(num, "≥ 3")
		fallthrough
	case 2:
		fmt.Println(num, "≥ 2")
		fallthrough
	default:
		fmt.Println(num, "≥ 1")
	}
	fmt.Println("")
}

3 예제 2[ | ]

package main

import "fmt"

func main() {
	printDigitInfo(3)
	printDigitInfo(2)
	printDigitInfo(1)
}

func printDigitInfo(num int) {
	switch num {
	case 3:
	case 2:
	case 1:
		fmt.Println(num, "≥ 1")
	}
}
package main

import "fmt"

func main() {
	printDigitInfo(3)
	printDigitInfo(2)
	printDigitInfo(1)
}

func printDigitInfo(num int) {
	switch num {
	case 3:
		fallthrough
	case 2:
		fallthrough
	case 1:
		fmt.Println(num, "≥ 1")
	}
}
package main

import "fmt"

func main() {
	printDigitInfo(3)
	printDigitInfo(2)
	printDigitInfo(1)
}

func printDigitInfo(num int) {
	switch num {
	case 3, 2, 1:
		fmt.Println(num, "≥ 1")
	}
}

4 같이 보기[ | ]

5 참고[ | ]

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