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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,59 @@ leading spaces" or "return false") are to be interpreted with the meaning of the
manner, so long as the end result is equivalent. (In particular, the algorithms are intended to be
easy to follow, and not intended to be performant.)

<h4 id=algorithm-control-flow>Control flow</h4>

<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.

<a for=iteration>Continue</a> will skip over any remaining steps in an iteration, proceeding to the
next item. If no further items remain, the iteration will stop. <a for=iteration>Break</a> will skip
over any remaining steps in an iteration, and skip over any remaining items as well, stopping the
iteration.

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

<ol>
<li>
<p><a for=list>For each</a> |item| in |example|:
<ol>
<li>Perform |operation| on |item|.
</ol>
</li>
</ol>

<p>The following prose would perform |operation| upon 1, then 2, then 4. 3 would be skipped.

<ol>
<li>
<p><a for=list>For each</a> |item| in |example|:
<ol>
<li>If |item| is 3, then <a for=iteration>continue</a>.
<li>Perform |operation| on |item|.
</ol>
</li>
</ol>

<p>The following prose would perform |operation| upon 1, then 2. 3 and 4 would be skipped.

<ol>
<li>
<p><a for=list>For each</a> |item| in |example|:
<ol>
<li>If |item| is 3, then <a for=iteration>break</a>.
<li>Perform |operation| on |item|.
</ol>
</li>
</ol>
</div>


<h3 id=terminology>Terminology</h3>

Expand Down Expand Up @@ -426,6 +473,7 @@ for each pair of converted key/original value. [[!WEBIDL]]

<p>Many thanks to
Michael™ Smith,
Mike West,
Philip Jägenstedt,
and Simon Pieters
for being awesome!
Expand Down