diff --git a/courses/fundamentals_of_ada/080_expressions/02-membership_tests.rst b/courses/fundamentals_of_ada/080_expressions/02-membership_tests.rst index 4ff69f053..d32c3b18a 100644 --- a/courses/fundamentals_of_ada/080_expressions/02-membership_tests.rst +++ b/courses/fundamentals_of_ada/080_expressions/02-membership_tests.rst @@ -42,20 +42,29 @@ Testing Constraints Via Membership Testing Non-Contiguous Membership ----------------------------------- -* Uses vertical bar "choice" syntax +* We use :ada:`in` to indicate membership in a range of values -.. code:: Ada + .. code:: Ada + + if Color in Red .. Green then + if Index in List'Range then + +* But what if the values are not contiguous? + + * We could use a Boolean conjunction + + .. code:: Ada + + if Index = 1 or Index = 3 or Index = 5 then + + * Or we could simplify it by specifying a collection (or set) + + .. code:: Ada + + if Index in 1 | 3 | 5 then - declare - M : Month_Number := Month (Clock); - begin - if M in 9 | 4 | 6 | 11 then - Put_Line ("31 days in this month"); - elsif M = 2 then - Put_Line ("It's February, who knows?"); - else - Put_Line ("30 days in this month"); - end if; + * **|** is used to separate members + * So :ada:`1 | 3 | 5` is the set for which we are verifying membership .. language_version 2012 @@ -81,7 +90,7 @@ Which condition(s) is (are) legal? Explanations - A. To use :ada:`or`, both sides of the comparison must be duplicated (e.g. :ada:`Today = Mon or Today = Wed`) + A. :ada:`Wed` and :ada:`Fri` are not Boolean expressions - need to compare each of them to :ada:`Today` B. Legal - should always return :ada:`True` C. Legal - returns :ada:`True` if :ada:`Today` is :ada:`Sat` or :ada:`Sun` D. Legal - returns :ada:`True` if :ada:`Today` is :ada:`Tue` or :ada:`Thu`