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

[SR-7708] labeled do statement can be looped with continue #50248

Closed
jepers opened this issue May 16, 2018 · 6 comments
Closed

[SR-7708] labeled do statement can be looped with continue #50248

jepers opened this issue May 16, 2018 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@jepers
Copy link

jepers commented May 16, 2018

Previous ID SR-7708
Radar None
Original Reporter @jepers
Type Bug
Status Closed
Resolution Invalid
Environment

Xcode 9.3.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 5a08a836c5a5ffc957c552bd92031f8f

is duplicated by:

  • SR-15234 Labeled do statements allow continue which lead to loop

Issue Description:

The following program:

var x = 3
label: do {
    print(x)
    x -= 1
    if x > 0 { continue label }
}

compiles and outputs:

3
2
1

I guess continue is not meant to work with do statements.

Related forum posts:
https://forums.swift.org/t/a-few-questions-about-defer-s-behavior/12266/32
https://forums.swift.org/t/intended-behavior-of-continue-in-repeat-while/12354/6

@palimondo
Copy link
Mannequin

palimondo mannequin commented May 16, 2018

Is this a GOTO?!?

@rjmccall
Copy link
Member

This is intended behavior. break and continue don't normally consider do, but if you explicitly label it, it's obvious enough what you're trying to do, and there's no real reason to restrict it.

@belkadan
Copy link
Contributor

We don't allow it for if or switch, though.

@jepers
Copy link
Author

jepers commented May 17, 2018

And I can't find any documentation of `continue` being allowed for `do`.

@rjmccall
Copy link
Member

It's unclear what the meaning of `continue` would be for `if` and `switch`, since those are multi-clause statements with one or more controlling expressions, whereas there's really no ambiguity about what continuing a `do` should mean. Also, being able to explicitly repeat a block of code that doesn't normally repeat can be quite useful, and you can't express that with normal loops without creating an artificial variable `while`-loop on.

@jepers
Copy link
Author

jepers commented May 18, 2018

OK, I filed SR-7721 requesting documentation for this behavior.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants