Conditional structures: Difference between revisions
m
→case without a default: the error discussed isn’t syntactic
(add RPL) |
m (→case without a default: the error discussed isn’t syntactic) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 2:
{{Control Structures}}
[[Category:Simple]]
[[Category:Flow control]]
;Task:
Line 587 ⟶ 588:
);</syntaxhighlight>
====case expressions====
Using the same example above, we assume that the
<syntaxhighlight lang="ada">Result := (case Op is
Add => A + B,
Line 596 ⟶ 597:
</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.
===case with a default alternative===
<syntaxhighlight lang="ada">type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
Line 613 ⟶ 615:
===case without a default===
When there is no '''when others''' clause, the compiler will complain about any uncovered alternative. This defends against a common reason for bugs in other languages.
I.e., the following code is
<syntaxhighlight lang="ada">case Today is
Line 625 ⟶ 627:
end case;</syntaxhighlight>
The
<syntaxhighlight lang="ada">case Today is
|