what is different range function with range keyword in go language ?
func main(){
s := []int{10, 20, 30, 40, 50, 60, 70, 80, 90}
for i,j:= range s{
fmt.Printf("%d => ",i)
fmt.Println(j)
}
}
different with
func main(){
s := []int{10, 20, 30, 40, 50, 60, 70, 80, 90}
for i,j:= range(s){
fmt.Printf("%d => ",i)
fmt.Println(j)
}
}
There is no range
function in Go. There is only the range
keyword.
What's confusing you is the optional parenthesis in your second example. These parenthesis are, as mentioned, optional, so the gofmt tool will remove them.
But there is no difference between range x
and range(x)
.