Labels in Go allow break and continue statements to target specific loops or blocks, enabling you to exit or skip multiple nested levels at once. Define a label before a statement, then reference that label in your control flow command.
outerLoop:
for i := 0; i < 10; i++ {
for j := 0; j < 10; j++ {
if j == 5 {
break outerLoop // Exits both loops immediately
}
}
}
Use continue outerLoop to skip the rest of the current iteration of the outer loop and jump to its next iteration.