What happens if there is no match in a switch statement in Go and there is no default case?

  • It will cause a compile-time error.
  • It will execute the code block of the case immediately following the switch statement.
  • It will result in a runtime panic.
  • The program will compile without any errors, but it will not execute the switch block.
In Go, if there is no match in a switch statement and no default case is provided, it will simply exit the switch statement without executing any code block. Therefore, the execution continues with the code block following the switch statement.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *