mmcgrana / gobyexample

Go by Example
https://gobyexample.com
7.18k stars 1.26k forks source link

Believe the for range loop is incorrectly referencing an integer #548

Closed crazicrow closed 1 month ago

crazicrow commented 1 month ago

Hi - The for range loop annotation on: https://gobyexample.com/for

Has the text "Another way of accomplishing the basic 'do this N times' iteration is range over an integer."

However I believe range actually doesn't work on an integer, and is only for an array, slice, string, map, or channel.

Trying to use range on a int gave me errors, and this also seems to be backed up on go documentation page: https://go.dev/wiki/Range

If I am wrong though I accept that and apologise for wasting time.

eliben commented 1 month ago

https://github.com/mmcgrana/gobyexample?tab=readme-ov-file#what-version-of-go-is-required-to-run-these-examples