Skip to content

Commit 8695ef2

Browse files
committed
pop
1 parent b52d9a7 commit 8695ef2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

slice/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
s := []int{1, 2, 3, 4, 5}
9+
for {
10+
if len(s) == 0 {
11+
break
12+
}
13+
14+
v := s[0] // get first element
15+
s = s[1:] // pop first element
16+
fmt.Printf("v: %v; s: %v; cap(%d); len(%d) \n", v, s, cap(s), len(s))
17+
}
18+
}

0 commit comments

Comments
 (0)