Skip to content

Update range-iteration concept docs#3060

Open
BNAndras wants to merge 4 commits intoexercism:mainfrom
BNAndras:update-range-iteration-docs
Open

Update range-iteration concept docs#3060
BNAndras wants to merge 4 commits intoexercism:mainfrom
BNAndras:update-range-iteration-docs

Conversation

@BNAndras
Copy link
Copy Markdown
Member

@BNAndras BNAndras commented Apr 7, 2026

Related to #3042

Comment thread concepts/range-iteration/about.md Outdated

You now have the knowledge on how to iterate a slice, or a map, in Go.
In Go, `range` iterates over slices, arrays, maps, strings, and channels.
Each iteration yields two values: the index (or key) and a copy of the element at that position.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't broadly true. It's true for ranging over slices, arrays, maps and strings. It's not true for channels, iterators and range int. It probably shouldn't be stated as generally true.

I think it's generally true that range yields one or two values. We probably want to mention iterators. They're used a fair bit in, say, the strings package, eg strings.FieldsSeq() or strings.SplitSeq()

Comment thread concepts/range-iteration/about.md Outdated
BNAndras and others added 2 commits April 6, 2026 22:16
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
@@ -1,8 +1,10 @@
{
"blurb": "Go has a special \"for range\" loop to easily iterate over collections of data.",
"blurb": "The for range loop iterates over slices, arrays, maps, strings, and channels.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and iterators? Or leave it vauge?

# About

You now have the knowledge on how to iterate a slice, or a map, in Go.
In Go, `range` iterates over slices, arrays, maps, and strings.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And more :)

In Go an unused variable will raise an error at build time.
Sometimes you only need the value, as per the first example:
Go will not compile if a variable is declared but never used.
If only the value is needed, assign the index or key to `_` to ignore it.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should probably be moved after the codeblock.

~~~~

## Iteration omitting key or value
## Omitting Index or Value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this come after all the range-types? Should we cover ranging over strings? Channels? Maybe mention channels are a later concept?

@IsaacG IsaacG added x:action/improve Improve existing functionality/content x:module/concept Work on Concepts x:type/content Work on content (e.g. exercises, concepts) x:type/docs Work on Documentation x:size/medium Medium amount of work x:rep/medium Medium amount of reputation labels Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:action/improve Improve existing functionality/content x:module/concept Work on Concepts x:rep/medium Medium amount of reputation x:size/medium Medium amount of work x:type/content Work on content (e.g. exercises, concepts) x:type/docs Work on Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants