Skip to content

Commit 2128f17

Browse files
Resolve "Expressions: Membership Tests Quiz - Add information prior to quiz outlining usage of "or""
1 parent d8132da commit 2128f17

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

courses/fundamentals_of_ada/080_expressions/02-membership_tests.rst

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,29 @@ Testing Constraints Via Membership
4242
Testing Non-Contiguous Membership
4343
-----------------------------------
4444

45-
* Uses vertical bar "choice" syntax
45+
* We use :ada:`in` to indicate membership in a range of values
4646

47-
.. code:: Ada
47+
.. code:: Ada
48+
49+
if Color in Red .. Green then
50+
if Index in List'Range then
51+
52+
* But what if the values are not contiguous?
53+
54+
* We could use a Boolean conjunction
55+
56+
.. code:: Ada
57+
58+
if Index = 1 or Index = 3 or Index = 5 then
59+
60+
* Or we could simplify it by specifying a collection (or set)
61+
62+
.. code:: Ada
63+
64+
if Index in 1 | 3 | 5 then
4865
49-
declare
50-
M : Month_Number := Month (Clock);
51-
begin
52-
if M in 9 | 4 | 6 | 11 then
53-
Put_Line ("31 days in this month");
54-
elsif M = 2 then
55-
Put_Line ("It's February, who knows?");
56-
else
57-
Put_Line ("30 days in this month");
58-
end if;
66+
* **|** is used to separate members
67+
* So :ada:`1 | 3 | 5` is the set for which we are verifying membership
5968

6069
..
6170
language_version 2012
@@ -81,7 +90,7 @@ Which condition(s) is (are) legal?
8190

8291
Explanations
8392

84-
A. To use :ada:`or`, both sides of the comparison must be duplicated (e.g. :ada:`Today = Mon or Today = Wed`)
93+
A. :ada:`Wed` and :ada:`Fri` are not Boolean expressions - need to compare each of them to :ada:`Today`
8594
B. Legal - should always return :ada:`True`
8695
C. Legal - returns :ada:`True` if :ada:`Today` is :ada:`Sat` or :ada:`Sun`
8796
D. Legal - returns :ada:`True` if :ada:`Today` is :ada:`Tue` or :ada:`Thu`

0 commit comments

Comments
 (0)