Slices, loops, and conditions
package main
import "fmt"
func main() {
numbers := []int{3, 8, 12, 5, 10}
for _, number := range numbers {
if number%2 == 0 {
fmt.Println(number)
}
}
}
Practice typing real code syntax, including brackets, punctuation, and indentation. Snippets are for typing practice only and are never executed.
package main
import "fmt"
func main() {
numbers := []int{3, 8, 12, 5, 10}
for _, number := range numbers {
if number%2 == 0 {
fmt.Println(number)
}
}
}
package main
import "fmt"
type Rectangle struct {
width float64
height float64
}
func (r Rectangle) Area() float64 {
return r.width * r.height
}
func main() {
shape := Rectangle{width: 6, height: 4}
fmt.Printf("Area: %.1f\n", shape.Area())
}
package main
import "fmt"
func main() {
words := []string{"go", "code", "go", "learn"}
counts := make(map[string]int)
for _, word := range words {
counts[word]++
}
fmt.Println(counts)
}