Case Structure Pseudo code

The Case structure can be used in place of a series of If ..ElseIf.. statements.

So instead of

Input a Grade

If the Grade >= 100 Then
    Report “Perfect Score”
ElseIf the Grade > 89 Then
    Report “Grade = A”
ElseIf the Grade > 79 Then
    Report “Grade = B”
ElseIf the Grade > 69 Then
    Report “Grade = C”
ElseIf the Grade > 59 Then
    Report “Grade = D”
Else
    Report “Grade = F”
End If


You

Input a Grade

Case based on Grade
    Case >=100
        Report “Perfect Score”
    Case > 89
        Report “Grade = A”
    Case > 79
        Report “Grade = B”
    Case > 69
        Report “Grade = C”
    Case > 59
        Report “Grade = D”
    Default
        Report “Grade = F”
End Case

Each condition is evaluated using the expression or value identified at the top of the structure in the order they appear. As soon as a condition evaluates to True the statements that follow it are executed and Then control passes to the statements following the End Case.

Note: You can replace an If...Then...ElseIF…. structure with a Select Case structure only if the If statement and each ElseIf statement evaluates the same expression.