How to Use goto in Go (And Why You Usually Shouldn't)

Use goto to jump to a label in Go, but prefer structured control flow for readability.

Use goto to jump to a labeled statement within the same function, but avoid it for general control flow as it often creates unreadable code.

for i := 0; i < 10; i++ {
    if i == 5 {
        goto end
    }
    fmt.Println(i)
}
end:
fmt.Println("Done")

Prefer structured alternatives like break, return, or helper functions to maintain clarity.