Go continue jumps over a for iteration [duplicate]

1 day ago 1
ARTICLE AD BOX

it's normal that you're not displaying the 5, because i represents the iterator, not the element in the range.
You need to separate the iterator from the element in the range:

func main() { for i, v := range []int{1, 2, 3, 4, 5} { // i == iterator (0, 1, 2, 3, 4) // v == element in range (1, 2, 3, 4, 5) if v%2 == 0 { continue } fmt.Println("Itérator: ", i) fmt.Println("Element :", v) } }

The result:

Iterator: 0 Element : 1 Iterator: 2 Element : 3 Iterator: 4 Element : 5
Read Entire Article