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

Control flow for loops #22

Closed
annevk opened this issue Nov 10, 2016 · 6 comments
Closed

Control flow for loops #22

annevk opened this issue Nov 10, 2016 · 6 comments

Comments

@annevk
Copy link
Member

annevk commented Nov 10, 2016

It would be great to have a less awkward way of phrasing to run a loop for the next item: https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke. Basically something like "continue".

@domenic
Copy link
Member

domenic commented Nov 10, 2016

HTML uses labels and "goto", but I guess that doesn't work great with foreach-style loops.

@annevk
Copy link
Member Author

annevk commented Nov 10, 2016

Not opposed to both. URL has goto too, although rewrites have been requested for many of the same reasons it's avoided everywhere else...

@mikewest
Copy link
Member

CSP uses "continue to the next item" in various places (https://w3c.github.io/webappsec-csp/#parse-serialized-policy for example). Since that's the way it's phrased in a variety of programming languages, phrasing it that way in the spec makes sense to me.

I'd suggest a template like the following:

  1. For each |item| in |list|:
    1. If we should skip |item| for some reason, continue to the next |item|.
    2. If we should stop the loop entirely, break.
    3. If we should skip out of this loop to a labeled step, continue to label.
    4. Do a thing to |item|.

@annevk
Copy link
Member Author

annevk commented Nov 17, 2016

I like "continue to label". I wonder if we can just use "continue" for the other kind, since there's no real reason to make that phrase more complicated and mentioning the variable there makes it seem like you're passing an argument (which is a thing we do with "return" and "throw" and "continue to").

And maybe we should have break as well?

If X, then continue.
If Y, then continue to Z.
If AA, then break.

@mikewest
Copy link
Member

SGTM.

domenic pushed a commit that referenced this issue Nov 21, 2016
This patch defines 'continue' and 'break' in the context of a 'for each' loop, and
provides simple examples of their usage.

This addresses pieces of #22, leaving
'continue to' for a subsequent patch.
@annevk
Copy link
Member Author

annevk commented Mar 17, 2017

#56 discusses labels as well so I think we can leave that there for now and consider this fixed by @mikewest. (I'll post a PR for DOM to make use of the new concepts and get rid of the old language.)

@annevk annevk closed this as completed Mar 17, 2017
annevk added a commit to whatwg/dom that referenced this issue Mar 17, 2017
annevk added a commit to whatwg/dom that referenced this issue Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants