On Wednesday, May 9, 2018 at 4:59:35 PM UTC-6, matthe...@gmail.com wrote:
>
> I’m not sure if C has been directly mentioned. I started with C so 
> iteration is just a nice shortcut to me. Assuming you’ve always had 
> collection iteration available an explanation is the for loop can make the 
> useful pattern of indexing into an array up to the length of the array 
> using an index variable.
>
> s := [5]int{0, 1, 2, 3, 4}
> // this C-style iteration prints 12345
> for i := 0; i < len(s); i++ {
>     fmt.Print(s[i]+1)
> }
>
> …except that in Go one would more naturally write

for _, e := range s {
fmt.Print(e + 1)
}

— Scott 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to