-
Notifications
You must be signed in to change notification settings - Fork 102
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
Conversation
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.
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". |
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. |
I took another pass at it. Should "return", "throw", "continue", and "break" be wrapped in |
Looks good. Would anyone ever reference these terms? |
No idea. shrug I suppose the indirection through "X depends on the Infra Standard" is enough, but |
One problem is that IDL defines throw too. We need to figure out how to reconcile with IDL, but ideally not right now. |
SGTM. |
Will let @domenic have a look too. |
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. |
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>. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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>. |
There was a problem hiding this comment.
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>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then break*
I'm happy to fix the remaining editorial problems once we sort out the export story. |
Fixed remaining editorial issues. |
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.