Ignoring how the break statement works

A break statement is commonly used to terminate the execution of a loop.

Mistake

	for i := 0; i < 5; i++ {
		switch i {
		default:
		case 2:
			break // this will break the switch statement not the loop
		}
	}

Fix

Using a label

loop:
	for i := 0; i < 5; i++ {
		switch i {
		default:
		case 2:
			break loop
		}
	}

References