Go for range

1 개요[ | ]

Go for range

2 문자열 배열[ | ]

package main

import "fmt"

func main() {
	fruits := []string{"apple", "banana", "lemon"}
	for i, fruit := range fruits {
		fmt.Println(i, fruit)
	}
}
package main

import "fmt"

func main() {
	nums := []string{"한놈", "두시기", "석삼"}
	for i, num := range nums {
		fmt.Println(i, num)
	}
}

3 문자열[ | ]

package main

import "fmt"

func main() {
	for i, ch := range "abc" {
		fmt.Println(i, ch)
	}
}
package main

import "fmt"

func main() {
	for i, ch := range "가나다" {
		fmt.Println(i, ch)
	}
}
package main

import "fmt"

func main() {
	for i, ch := range "Hi世界" {
		fmt.Println(i, ch)
	}
}

4 같이 보기[ | ]

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