Skip to content

Replace for ;; with for range int in all examples #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

mattnathan
Copy link
Contributor

I believe this to be more idiomatic of Go since it was introduced.

@mattnathan
Copy link
Contributor Author

mattnathan commented Jun 2, 2025

I thought I'd do a search (/for (\w+) := 0; \1 < (\d+|\w+); \1\+\+ \{/) over the other examples for places where range int could also be used and found candidates in these examples:

  1. arrays L48, L49
  2. goroutines L11
  3. mutexes L45
  4. rate limiting L47
  5. select L32
  6. slices L87, L90
  7. stateful goroutines L76, L92

I can add these to the PR if you think it'll be useful?

@eliben
Copy link
Collaborator

eliben commented Jun 2, 2025

I thought I'd do a search (/for (\w+) := 0; \1 < (\d+|\w+); \1\+\+ \{/) over the other examples for places where range int could also be used and found candidates in these examples:

1. arrays L48, L49

2. goroutines L11

3. mutexes L45

4. rate limiting L47

5. select L32

6. slices L87, L90

7. stateful goroutines L76, L92

I can add these to the PR if you think it'll be useful?

Yes, let's fold these into a single PR.

I can then review case by case to see what makes sense. I expect that most of them can be converted to the range loop. Initially I only added the new syntax to for, but now the feature has been around enough that it would make sense to replace all uses. Thanks in advance

This to be more idiomatic of Go since it was introduced.
@mattnathan mattnathan force-pushed the eg-atomic-counters-range branch from 51af642 to 1621089 Compare June 2, 2025 14:28
@mattnathan mattnathan changed the title Replace for ;; with for range int in atomic counters Replace for ;; with for range int in all examples Jun 2, 2025
@mattnathan
Copy link
Contributor Author

That's done now

@eliben eliben merged commit 10aea2d into mmcgrana:master Jun 2, 2025
2 checks passed
@mattnathan mattnathan deleted the eg-atomic-counters-range branch June 2, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants