Switch#

switch 문은 조건부 분기를 처리한다.

Blank Switch#

Blank switch는 expression이 없는 switch 문이다. switch true와 동일하게 작동하며, 긴 if-else-if 체인을 깔끔하게 작성할 때 사용한다.

eg.

switch {
case x < 0:
    return -x
case x == 0:
    return 0
default:
    return x
}

Initialization Statement#

switch 문 시작 부분에 짧은 initialization statement를 포함할 수 있다. 여기서 선언된 변수는 switch 블록 내에서만 유효하다.

eg.

switch x := f(); {
case x < 0:
    return -x
default:
    return x
}

# go