Skip to content
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

spec: description of continue statements is not accurate #48864

Closed
DQNEO opened this issue Oct 8, 2021 · 5 comments
Closed

spec: description of continue statements is not accurate #48864

DQNEO opened this issue Oct 8, 2021 · 5 comments
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@DQNEO
Copy link
Contributor

DQNEO commented Oct 8, 2021

Current spec says:

go/doc/go_spec.html

Lines 5618 to 5622 in 2ac3bdf

<p>
A "continue" statement begins the next iteration of the
innermost <a href="#For_statements">"for" loop</a> at its post statement.
The "for" loop must be within the same function.
</p>

There are 2 problems.

Problems

  1. There is no "post statement" in "For statements with range clause"
    An implementation may have an internal post statement, but it's not declared in the spec.
  2. Given that "The condition is evaluated before each iteration.", the next iteration may not begin.
	for i := 1; i < 2; i++ {
		println(i)
		continue // the next iteration won't begin
	}

So I would like to propose a better description.

Proposal

- A "continue" statement begins the next iteration of the innermost "for" loop at its post statement. 
+ A “continue” statement causes a jump to the end of the current iteration of the innermost “for” loop.

If this is acceptable, then I'm willing to send a change for review.

@ianlancetaylor
Copy link
Contributor

CC @griesemer

@ianlancetaylor ianlancetaylor changed the title spec: Description of continue statements is not accurate spec: description of continue statements is not accurate Oct 8, 2021
@ianlancetaylor ianlancetaylor added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 8, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 8, 2021
@muirdm
Copy link

muirdm commented Oct 8, 2021

While we are tweaking, what about saying "the innermost enclosing for loop" to clarify that the "continue" must be within the loop?

@mdempsky
Copy link
Member

mdempsky commented Oct 8, 2021

I'm pretty sure I've suggested similarly before that continue's semantics should be worded as advancing control to the end of the for block. I'm not having any luck finding the issue or CL though.

Edit: Found it in golang-dev@ archives: https://groups.google.com/g/golang-dev/c/k6xUizt32Mw/m/Qmx5PNeGQo0J.

@griesemer
Copy link
Contributor

Thanks for bringing this up. Please hold off with sending a CL for now while we're in the middle of tweaking the spec for generics. Documentation improvements such as this one can be made any time later.

@griesemer griesemer self-assigned this Oct 12, 2021
@griesemer griesemer modified the milestones: Backlog, Go1.19 Mar 18, 2022
@gopherbot
Copy link

Change https://go.dev/cl/405756 mentions this issue: spec: clarify "continue" statement

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants