Skip to content

Commit

Permalink
Define conditional statements
Browse files Browse the repository at this point in the history
Fixes #180.
  • Loading branch information
miketaylr authored Sep 26, 2023
1 parent 53fe02e commit a6ffd91
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,49 @@ the end result is indistinguishable. For instance, as long as |result| in the ab
mutated during a compute operation, the user agent could stop the computation.


<h3 id=algorithm-conditional-statements>Conditional statements</h3>

<p>Algorithms with conditional statements should use the keywords "if", "then", and "otherwise".

<div class=example id=example-conditional-statement>
<ol>
<li><p>Let |value| be null.

<li><p>If |input| is a <a>string</a>, then set |value| to |input|.

<li><p>Return |value|.
</ol>
</div>

Once the keyword "otherwise" is used, the keyword "then" is omitted.

<div class=example id=example-conditional-statement-no-then-1>
<ol>
<li><p>Let |value| be null.

<li><p>If |input| is a <a>string</a>, then set |value| to |input|.

<li><p>Otherwise, set |value| to failure.

<li><p>Return |value|.
</ol>
</div>

<div class=example id=example-conditional-statement-no-then-2>
<ol>
<li><p>Let |value| be null.

<li><p>If |input| is a <a>string</a>, then set |value| to |input|.

<li><p>Otherwise, if |input| is a <a>list</a> of <a>strings</a>, set |value| to |input|[0].

<li><p>Otherwise, throw a {{TypeError}}.

<li><p>Return |value|.
</ol>
</div>


<h3 id=algorithm-iteration>Iteration</h3>

<p>There's a variety of ways to repeat a set of steps until a condition is reached.
Expand Down Expand Up @@ -2051,6 +2094,7 @@ Malika Aubakirova,
Martin Thomson,
Michael™ Smith,
Mike West,
Mike Taylor,
Ms2ger,
Pavel "Al Arz" Kurochkin,
Philip Jägenstedt,
Expand Down

0 comments on commit a6ffd91

Please sign in to comment.