N
N
NubasLol2019-07-10 16:02:09
go
NubasLol, 2019-07-10 16:02:09

How switch works?

test1 := false
  test2 := true
  test3 := false

  switch {
  case test1:
    fmt.Println(1)
    fallthrough
  case test2:
    fmt.Println(2)

    fallthrough

  case test3:
    fmt.Println(3)
  }

Outputs 2.3. Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2019-07-10
@NubasLol

This is described in the specification for the goshka.
That is, fallthrough transfers control to the first line of the next case without checking any conditions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question