You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What version of Go are you using (go version)? using go player
$ go version
Does this issue reproduce with the latest release? i do not know just check golang with go player
What operating system and processor architecture are you using (go env)? window 10 with Chrom
go env Output
$ go env
What did you do? checking golan slice with for using len() the the condition like "i < len(x) and the result you can see
//golang slice and "for" question
// when i use len(x) the output is not what i want.
// because the len(x) change the size auto and the len(x) also change inside for
// so the problem looks like when "for" condition check repeat not make const when first call for for with repating
// answer with sfbanghm.yahoo.com
package main
import (
"fmt"
)
func RmBack (arr []int) ([]int, int) {
//var arrLen int
//arrLen = len(arr)
return arr[:len(arr)-1], arr[len(arr)-1]
// for front
//return arr[1:], arr[0]
}
func main() {
fmt.Println("Hello, playground")
// slice a[starI: endi] a(starti- endi] endindex not include
x := []int {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
px := &x
xOrg := *px
fmt.Printf("xAdd: %p, pxAdd: %p\n", x, *px)
fmt.Println("xAdd: ",x, "pxAdd: ", *px)
y := x[4:8] //
fmt.Println("x: [0 1 2 3 4 5 6 7 8 9 10]")
fmt.Println("x: ",x, " y: ", y)
//out=>x: [0 1 2 3 4 5 6 7 8 9 10]
//out=>x: [1 2 3 4 5 6 7 8 9 10] y: [5 6 7 8]
fmt.Printf("xadd:%p, yadr:%p, x[4]adr:%p \n",x, y, &x[4])
//out=>xadd:0xc000012050, yadr:0xc000012070, x[4]adr:0xc000012070
fmt.Println(x, len(x))
//if useing len(x) and RmBack some how it dose not work as i except like len(x) 10
var rmVal int
for i := 0; i < 10 ; i++{
x, rmVal = RmBack(x)
fmt.Println("index: ",i,"x: ",x," rmVal: ",rmVal)
}
fmt.Println("xAdd: ",x, "pxAdd: ", *px," xorg: ",xOrg)
// using len(u) at condtion of "for" and result is not what I want
// at the "for" dose not make len(u) as constant at the call of "for"
u := []int {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i := 0; i < len(u) ; i++{
u, rmVal = RmBack(u)
fmt.Println("index: ",i,"x: ",u," rmVal: ",rmVal)
}
}
the Go project does not use its bug tracker for general discussion or asking questions about the language. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.
Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!
What version of Go are you using (
go version
)? using go playerDoes this issue reproduce with the latest release? i do not know just check golang with go player
What operating system and processor architecture are you using (
go env
)? window 10 with Chromgo env
OutputWhat did you do? checking golan slice with for using len() the the condition like "i < len(x) and the result you can see
//output
What did you expect to see? you can see above two output must to be same
What did you see instead? when slice auto change the len by RmBack function and for condition repeat check len(x) and terminate for loop
The text was updated successfully, but these errors were encountered: