Pseudocode Syntax Cheatsheet

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Pseudocode Syntax A-Z

1. Declaring a variable 5B. CASE OF ... OTHERWISE ... ENDCASE

X <- 5 INPUT FoodToBuy


name <- “Adam” CASE OF FoodToBuy
Milo : OUTPUT “Here’s your milo”
2. Mathematical operators Biscuit: OUTPUT “Here’s your
biscuit”
OTHERWISE: OUTPUT “The
canteen does not have this food”
ENDCASE

6. Iterations (Repeat)
6A. FOR ... TO ... NEXT ...
- Used when the number of
iterations is fixed.
3. Comparison operators FOR Counter <- 1 TO 10
OUTPUT Counter
NEXT

6B. REPEAT ... UNTIL ...


- Used when the number of
iterations is not known, that is
completed at least once.
4. Declaring an array (a variable that stores a REPEAT
list of items). OUTPUT “Hello”
INPUT Option
DECLARE MyClass : ARRAY[1:10] OF UNTIL Option = -1
STRING
6C. WHILE ... DO ... ENDWHILE
DECLARE = Keywords
- Used when the number of
MyClass = variable name (can be any name
iterations is not known, that may
you like)
never be completed even once
ARRAY[1:10] = Create an array of size 10
OF STRING = The data type of the array
- STRING = “WORD” Total <- 0
- INTEGER = NUMBERS (eg. 5, 6) OUTPUT “Enter value for mark, -1 to finish”
- FLOAT = Decimal number (eg. 5.6) INPUT Mark
WHILE Mark <> -1 DO
To access the Nth element of an array, do: Total <- Total + Mark
ArrayName[N], where N is the position OUTPUT “Enter value for mark, -1
to finish”
5. Conditionals INPUT Mark
5A. IF ... THEN ... ELSE ... ENDIF ENDWHILE
INPUT Age
IF Age < 18
THEN
5B. CASE OF ... OTHERWISE ... ENDCASE
OUTPUT “Child”
ELSE
OUTPUT “Adult”
ENDIF

You might also like