언어/Golang

switch

SYeonni 2022. 8. 2. 20:50
package main

import (
	"fmt"
	"math/rand"
)

func Num(random int) int {

	random -= rand.Intn(10)

	return random
}

func main() {

	result := Num(rand.Intn(39))

	switch {
	case result > 10:
		fmt.Println("10보다 작다")
	case result < 10:
		fmt.Println("10보다 크다")

	}

	fmt.Printf("끝")

}

 

c언어와 달리 switch 문에 break 가 없다.

728x90