7. Case

Match-case statements are in python from 3.10.
Python refers to this as structural pattern matching.
Match-case statements can be used for what is known as switch-case statements in general use in other languages.

7.1. Match-case

Multiple cases can be used.
Each case is checked in order until a matching case is found.
The simple pattern in python is:
match subject:
    case <pattern_1>:
        <action_1>
    case <pattern_2>:
        <action_2>
An example in python is:
age = int(input("Enter your age: "))
if age >= 13:
    age_flag = True
else:
    age_flag = False

match age_flag:
    case True:
        print("Entry permitted")
    case False:
        print("No entry until you reach 13 years of age.")
Pseudocode. The equivalent pseudocode is:
BEGIN
    INPUT age
    IF age >= 13 THEN
        age_flag ← TRUE
    ELSE
        age_flag ← FALSE
    ENDIF

    CASE age_flag OF
        TRUE:
            PRINT "Entry permitted"
        FALSE:
            PRINT "No entry until you reach 13 years of age."
    ENDCASE
END

7.2. Alternatives

Several alternatives can be used in a single pattern using the pipe symbol for or: |.
grade = "A"
match grade:
    case  "A+" | "A" | "B+" |  "B" | "C+" | "C":
        print("Acceptable standard.")
    case "D+" | "D" | "NP" | "UG":
        print("Retest required.")
Pseudocode. The equivalent pseudocode is:
BEGIN
    grade ← "A"

    CASE grade OF
        "A+", "A", "B+", "B", "C+", "C":
            PRINT "Acceptable standard."
        "D+", "D", "NP", "UG":
            PRINT "Retest required."
    ENDCASE
END

7.3. Wildcard

If an exact match is not confirmed, the last case, if provided, will be used as the matching case.
The wildcard _ is usually used when it is not referred to again in the code block.
Another variable name, such as other, is used if it is referred to in the following case block code.
grade = "A-"
match grade:
    case "A+" | "A" | "B+" | "B" | "C+" | "C":
        print("Acceptable standard.")
    case "D+" | "D" | "NP" | "UG":
        print("Retest required.")
    case _:
        print("Not a valid grade")
Pseudocode. The equivalent pseudocode is:
BEGIN
    grade ← "A-"

    CASE grade OF
        "A+", "A", "B+", "B", "C+", "C":
            PRINT "Acceptable standard."
        "D+", "D", "NP", "UG":
            PRINT "Retest required."
        OTHERWISE:
            PRINT "Not a valid grade"
    ENDCASE
END

7.4. Matching tuples for coordinates

Other objects, apart from strings can be matched.
An example with a tuple is below.
point = (2, 3)
match point:
    case (0, 0):
        print("Origin")
    case (0, y):
        print(f"{y} on Y axis")
    case (x, 0):
        print(f"{x} on X axis")
    case (x, y):
        print(f"{x} on X axis, {y} on Y axis")
    case _:
        print("Invalid point")
Pseudocode. The equivalent pseudocode is:
BEGIN
    point ← (2, 3)

    CASE point OF
        (0, 0):
            PRINT "Origin"
        (0, y):
            PRINT f"{y} on Y axis"
        (x, 0):
            PRINT f"{x} on X axis"
        (x, y):
            PRINT f"{x} on X axis, {y} on Y axis"
        OTHERWISE:
            PRINT "Invalid point"
    ENDCASE
END

7.5. Pseudocode alternatives

In pseudocode, the code for each case can be on the same line as the case value.
The keywords: OF, OTHERWISE, can be used.
The OTHERWISE clause with its default sequence is optional.
The general pattern may be:
CASE expression OF
    condition 1 :
        sequence 1
    condition 2 :
        sequence 2
    ...
    condition n :
        sequence n
    OTHERWISE :
        default sequence
ENDCASE

Example:

BEGIN
    CASE Title OF
        "Mr":
            PRINT "Mister"
        "Mrs":
            PRINT "Missus"
        "Ms":
            PRINT "Miss"
        OTHERWISE:
            PRINT "Form of address not recognised"
    ENDCASE
END
Python. The equivalent python is:
title = "Ms"
match title:
    case "Mr":
        print("Mister")
    case "Mrs":
        print("Missus")
    case "Ms":
        print("Miss")
    case _:
        print("Form of address not recognised")