100% found this document useful (1 vote)
2K views

CASE Pseudocode

CASE statements allow code to execute different branches depending on a variable's value. A CASE statement specifies values to test for and the corresponding statements to execute, with an optional OTHERWISE clause to handle any values not explicitly tested. CASE statements are evaluated sequentially, executing the first matching statement and skipping remaining cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

CASE Pseudocode

CASE statements allow code to execute different branches depending on a variable's value. A CASE statement specifies values to test for and the corresponding statements to execute, with an optional OTHERWISE clause to handle any values not explicitly tested. CASE statements are evaluated sequentially, executing the first matching statement and skipping remaining cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CASE statements (8.1.

4 (b))
CASE statements allow one out of several branches of code to be executed, depending on the value of a variable.

CASE statements are written as follows:


CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
ENDCASE

An OTHERWISE clause can be the last case:

CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
OTHERWISE <statement>
ENDCASE

It is best practice to keep the branches to single statements as this makes the pseudocode more readable. Similarly,
single values should be used for each case. If the cases are more complex, the use of an IF statement, rather than a
CASE statement, should be considered.

Each case clause is indented by two spaces. They can be considered as continuations of the CASE statement rather
than new statements.

Note that the case clauses are tested in sequence. When a case that applies is found, its statement is executed, and
the CASE statement is complete. Control is passed to the statement after the ENDCASE. Any remaining cases are
not tested.

If present, an OTHERWISE clause must be the last case. Its statement will be executed if none of the preceding
cases apply.

Example – formatted CASE statement

INPUT Move
CASE OF Move
ꞌWꞌ : Position ← Position – 10
ꞌEꞌ : Position ← Position + 10
ꞌAꞌ : Position ← Position – 1
ꞌDꞌ : Position ← Position + 1
OTHERWISE OUTPUT "Beep"
ENDCASE

41

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy