220722

심우진·2022년 7월 22일
0
package main

import "fmt"

func plus(a ...int) int {
	var total int
	for _, item := range a {
		total += item
	}
	return total
}

func main() {
	name := "asdf;lkjasdf;lkjasdf"
	for _, letter := range name {
		fmt.Println(string(letter))
	}
}
package main

import "fmt"

func main() {
	foods := [3]string{"potato", "pizza", "pasta"}
	for _, food := range foods {
		fmt.Println(food)
	}
}
package main

import "fmt"

func main() {
	foods := [3]string{"potato", "pizza", "pasta"}
	for i := 0; i < len(foods); i++ {
		fmt.Println(foods[i])
	}
}
  • slice
package main

import "fmt"

func main() {
	foods := []string{"potato", "pizza", "pasta"}
	fmt.Printf("%v\n", foods)
	foods = append(foods, "tomato")
	fmt.Printf("%v\n", foods)
}

0개의 댓글