notexOPENOverview
Notex/Languages/Practice: switch and goto
02.18LESSON 18 OF 19 · 1 MIN READ

Practice: switch and goto

Always free to read

The following exercises let you explore switch statements and goto.

  1. Rewrite exercise 1 using a switch statement. Which version do you find more readable? Why?

  2. The following code should break out of the for loop when i == 5, but it doesn’t. Why not? Identify the cause and fix it:

go for i:= range 10 { switch i { case 5: break default: fmt.Println(i) } }

  1. Rewrite the code in the exercises/ex9 directory to use goto. Is it easier or harder to follow now? Why?
Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K