Skip to content

Define 'continue' and 'break' statements. #35

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 6 commits into from
Nov 21, 2016
Merged

Define 'continue' and 'break' statements. #35

merged 6 commits into from
Nov 21, 2016

Conversation

mikewest
Copy link
Member

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.

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.
@mikewest
Copy link
Member Author

WDYT, @annevk? I think it might be worthwhile to pull the iteration discussion out into a "Control Flow" section; I didn't do that in this patch, but I think it's worth doing before trying to define "continue to".

@annevk
Copy link
Member

annevk commented Nov 18, 2016

So I think rather than tying this to "for each" (of lists) I think we want to put this in the "Algorithms" section and leave it a little vaguer, but making it apply to all kinds of loops. "While", "for each", etc.

So group this together with where we define what "return" and "throw" result in.

As we flush that out more as time goes on it might warrant subsections indeed.

@mikewest
Copy link
Member Author

I took another pass at it.

Should "return", "throw", "continue", and "break" be wrapped in <dfn>? abstract-op perhaps?

@annevk
Copy link
Member

annevk commented Nov 18, 2016

Looks good. Would anyone ever reference these terms?

@mikewest
Copy link
Member Author

No idea. shrug I suppose the indirection through "X depends on the Infra Standard" is enough, but <a>continue</a> would be more explicit.

@annevk
Copy link
Member

annevk commented Nov 18, 2016

One problem is that IDL defines throw too. We need to figure out how to reconcile with IDL, but ideally not right now.

@mikewest
Copy link
Member Author

SGTM.

@annevk
Copy link
Member

annevk commented Nov 18, 2016

Will let @domenic have a look too.

- Add control flow subheading
- <dfn> continue/break
- numbers are not variables
- 1-space indent
@domenic
Copy link
Member

domenic commented Nov 18, 2016

I pushed some tweaks. I think it's important to define and export these things; specs might not want to always x-ref them, but they should at least have the option to do so.

I also grouped these and the return/throw thing under a heading, but I'm not 100% on that; let me know what you think.

Great examples, @mikewest.

@mikewest
Copy link
Member Author

Fixed a tiny typo in your fixups; otherwise LGTM. :)

<p>The control flow of algorithms is such that a requirement to "return" or "throw" terminates the
algorithm the statement was in. "Return" will hand the given value, if any, to its caller. "Throw"
will make the caller automatically rethrow the given value, if any, and thereby terminate the
caller's algorithm. Using prose the caller has the ability to "catch" the exception and perform
another action.

<p>An iteration's flow can be controlled via requirements to
<dfn export for=iteration>continue</dfn> or <dfn export for=iteration>break</dfn>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domenic if we export these, why not export return and throw? Is the plan to do that later once we figure things out with IDL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should wait there.


<div class=example id=example-break-continue>
<p>Let |example| be the <a>list</a> « 1, 2, 3, 4 ». The following prose would perform
<code>operation</code> upon 1, then 2, then 3, then 4:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using <code> since we generally don't want to invoke JavaScript APIs (those are marked up with <code>) from algorithms. Maybe <var>? (Applies below too.)

<li>
<p><a for=list>For each</a> |item| in |example|:
<ol>
<li>If |item| is 3, <a for=iteration>continue</a>.
Copy link
Member

@annevk annevk Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then continue*

<li>
<p><a for=list>For each</a> |item| in |example|:
<ol>
<li>If |item| is 3, <a for=iteration>break</a>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then break*

@annevk
Copy link
Member

annevk commented Nov 21, 2016

I'm happy to fix the remaining editorial problems once we sort out the export story.

@annevk
Copy link
Member

annevk commented Nov 21, 2016

Fixed remaining editorial issues.

@domenic domenic merged commit 8fbf990 into whatwg:master Nov 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants