Uploaded by Bilal.Jamal

Pseudocode-Syntax-Cheatsheet

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