mmcgrana / gobyexample

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

Incorrect code example in official documentation eg. usage of range #520

Closed RahulRana0707 closed 5 months ago

RahulRana0707 commented 5 months ago

Description: I found an issue with the code example provided in the official Go documentation while practicing. The code example is located https://gobyexample.com/for.

Issue Details: Location: The incorrect code example is located in the section for loop page of go by example website. Problem: Here, you're attempting to range over the integer 3, which is not valid syntax. The range keyword in Go is used to iterate over elements of a collection like arrays, slices, maps, or channels, but not a single integer Impact: This can confuse beginners who are learning from the official documentation. Proposed Solution: Provide a corrected version of the code example or remove it until it's fixed. Steps to Reproduce:

Navigate to the for loop page of go by example. Observe the code example provided. Notice the syntax errors and logic issues.

Expected Behavior: The code example should be correct and demonstrate the intended functionality.

Additional Information:

I'm using go by example to practice Go. Any additional context or information you think is relevant.

Thank you for your attention to this matter. Let me know if you need any further assistance.

eliben commented 5 months ago

PTAL at the release notes of Go 1.22: https://go.dev/blog/go1.22

And the spec at https://go.dev/ref/spec#RangeClause