Conditional structures: Difference between revisions
Content added Content deleted
Flexibeast (talk | contribs) (Add page to "Flow control" category.) |
m (→case expressions: Highlight variables in text as italic) |
||
Line 588: | Line 588: | ||
);</syntaxhighlight> |
);</syntaxhighlight> |
||
====case expressions==== |
====case expressions==== |
||
Using the same example above, we assume that the |
Using the same example above, we assume that the ''Operation'', ''Op'', and ''Result'' variables are declared. A case expression over the enumeration of operations might look like: |
||
<syntaxhighlight lang="ada">Result := (case Op is |
<syntaxhighlight lang="ada">Result := (case Op is |
||
Add => A + B, |
Add => A + B, |
||
Line 597: | Line 597: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
Note: some websites (particularly [https://www.radford.edu/nokie/classes/320/abe/operators.html#:~:text=if%20and%20case-,Examples%3A,1%2C%20others%20%3D%3E%200)%3B this one]) contain a different variant of a case expression (<syntaxhighlight lang="ada">case Op of...</syntaxhighlight>). The Ada Reference Manual indicates this is incorrect, and we use the [http://www.ada-auth.org/standards/12rm/html/RM-4-5-7.html formal version] here. |
Note: some websites (particularly [https://www.radford.edu/nokie/classes/320/abe/operators.html#:~:text=if%20and%20case-,Examples%3A,1%2C%20others%20%3D%3E%200)%3B this one]) contain a different variant of a case expression (<syntaxhighlight lang="ada">case Op of...</syntaxhighlight>). The Ada Reference Manual indicates this is incorrect, and we use the [http://www.ada-auth.org/standards/12rm/html/RM-4-5-7.html formal version] here. |
||
===case with a default alternative=== |
===case with a default alternative=== |
||
<syntaxhighlight lang="ada">type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); |
<syntaxhighlight lang="ada">type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); |