-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrange.go
39 lines (27 loc) · 778 Bytes
/
range.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import "fmt"
//iterating over data structures
func main(){
nums:=[]int {6,7,8}
//normal way to iterate
//for i:=0;i<len(nums);i++{
//fmt.Println(nums[i])
//}
//sum:=0
for i ,num:=range nums{ //i=index
//sum=sum+num
//fmt.Println(num)
fmt.Println(num,i)
}
//fmt.Println(sum)
m:=map[string]string{"fname":"john","lname":"doe"}
for k,v:=range m{
fmt.Println(k,v)
}
//range for string
for i,c:=range "golang"{
fmt.Println(i,c) //unicode code point "rune"(data structure) for alpjhabets -output
} //starting byte of rune
//255-.1 byte ,2 bytes if more than 255(unicode has more than 255 as of assci value)
//fmt.Println(i,string(c)) //for character printing
}