Complete the code to exit the loop when i equals 3.
for i := 1; i <= 5; i++ { if i == 3 { [1] } fmt.Println(i) }
The break statement exits the nearest enclosing loop immediately.
Complete the code to stop the loop when the character 'x' is found in the string.
str := "golang" for _, ch := range str { if ch == '[1]' { break } fmt.Printf("%c", ch) }
The loop breaks when the character 'x' is found, stopping the printing.
Fix the error in the loop to break when the number is greater than 10.
nums := []int{5, 8, 12, 3}
for _, num := range nums {
if num [1] 10 {
break
}
fmt.Println(num)
}The condition should check if the number is greater than 10 to break the loop.
Fill both blanks to create a map of squares for numbers greater than 2.
squares := map[int]int{}
for i := 1; i <= 5; i++ {
if i [1] 2 {
squares[i] = i [2] i
}
}The loop adds squares of numbers greater than 2 using the multiplication operator.
Fill the blanks to create a map of uppercase keys and values greater than 0.
import "strings" data := map[string]int{"a": 1, "b": 0, "c": 3} result := map[string]int{} for k, v := range data { if v [1] 0 { result[[2]] = v } } fmt.Println(result)
The loop adds entries with values greater than 0, using uppercase keys.
