Complete the code to print each number in the array.
numbers := [3]int{1, 2, 3} for [1] := 0; i < len(numbers); i++ { fmt.Println(numbers[i]) }
The variable i is commonly used as the index in for loops. Here, it iterates from 0 to the length of the array.
Complete the code to use a range loop to print each element in the array.
numbers := [3]int{4, 5, 6} for [1], value := range numbers { fmt.Println(value) }
The variable i is commonly used as the index in range loops. It is ignored here but must be declared.
Fix the error in the for loop to correctly iterate over the array.
arr := [3]string{"a", "b", "c"} for i := 0; i <= len(arr); i++ { fmt.Println(arr[[1]]) }
The loop should use i as the index. The condition should be i < len(arr) to avoid out-of-range errors.
Fill both blanks to create a map of words and their lengths for words longer than 3 characters.
words := []string{"go", "code", "fun", "learn"}
lengths := map[string]int{word: [1] for _, word := range words if [2]The map stores the length of each word. The condition filters words longer than 3 characters.
Fill all three blanks to create a map of uppercase words and their lengths for words with length greater than 2.
words := []string{"go", "code", "fun", "learn"}
lengths := map[string]int[1]: [2] for _, word := range words if [3]The map keys are uppercase words, values are their lengths, filtered by length greater than 2.