Skip to content

Commit 95f50ce

Browse files
committed
Adds range egs
1 parent 5798236 commit 95f50ce

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

codes/ch4_looping/range.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import "fmt";
4+
5+
type Profile struct {
6+
name string
7+
role string
8+
}
9+
10+
func main() {
11+
12+
slice := []Profile {
13+
{"Ashwin", "Sr. Fullstack Engineer"},
14+
{"Kumar", "Sr. Engineering Manager"},
15+
{"Saju", "Sr. Solution Architect"},
16+
{"Ajay", "Sr. Solution Architect"}, // comma is needed here
17+
}
18+
19+
/**
20+
* _ is index; we are not using it; thus replacing with _
21+
*/
22+
for _, employee := range slice {
23+
fmt.Println("Profile: " + employee.name + " (" + employee.role + ")" )
24+
}
25+
26+
}

0 commit comments

Comments
 (0)