Go foreach

1 개요[ | ]

Go foreach
Foreach Loops - The Go Way

2 배열[ | ]

package main

import "fmt"

func main() {
	fruits := []string{"Apple", "Banana", "Orange"}
	for _, fruit := range fruits {
		fmt.Println(fruit)
	}
}
package main

import "fmt"

func main() {
	fruits := []string{"Apple", "Banana", "Orange"}
	for i, fruit := range fruits {
		fmt.Println(i, fruit)
	}
}

3[ | ]

package main

import "fmt"

func main() {
	d := map[string]string{"id":"42", "name":"John Smith", "birthyear":"2000"}
	for k, v := range d {
		fmt.Println(k, v)
	}
}
package main

import "fmt"

func main() {
	d := map[string]interface{}{"id":42, "name":"John Smith", "birthyear":2000}
	for k, v := range d {
		fmt.Println(k, v)
	}
}

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}