Psuedocode<3

Cards (47)

  • The consistent style of pseudo-code used in assessments ensures that students will understand the syntax with enough preparation
  • Students are directed to ensure their code is clear, consistent, and unambiguous when answering questions or describing algorithms written in pseudo-code
  • The resource on pseudo-code may be updated as required and the latest version will always be available on the website
  • The names of constants in pseudo-code will always be written in capitals
  • Arithmetic operations
    • +
    • -
    • *
    • /
    • DIV
    • MOD
  • Relational operators
    • <
    • >
    • =
    • !=
    • <=
    • >=
    • AND
    • OR
    • NOT
  • Variable assignment
    1. a ← 3
    2. b ← a + 1
    3. c'Hello'
  • Constant assignment
    1. CONSTANT PI ← 3.141
    2. CONSTANT CLASS_SIZE ← 23
  • Indefinite (condition controlled) iteration - REPEAT-UNTIL
    1. REPEAT
    2. UNTIL BoolExp
  • Indefinite (condition controlled) iteration - WHILE-ENDWHILE
    1. WHILE
    2. ENDWHILE
  • Indefinite (condition controlled) iteration
    1. REPEAT-UNTIL (repeat the statements until the Boolean expression is True)
    2. REPEAT...UNTIL BoolExp
    3. WHILE-ENDWHILE (while the Boolean expression is True, repeat the statements)
  • REPEAT-UNTIL
    Repeat the statements until the Boolean expression is True
  • WHILE-ENDWHILE
    While the Boolean expression is True, repeat the statements
  • Definite (count controlled) iteration
    1. FOR-TO-[STEP]-ENDFOR (If STEP IntExp is missing it is considered to be 1)
    2. FOR IdentifierIntExp TO IntExp [STEP IntExp]...ENDFOR
    3. FOR-IN-ENDFOR (repeat the statements the number of times that there are characters in a string)
  • FOR-TO-[STEP]-ENDFOR
    If STEP IntExp is missing it is considered to be 1
  • FOR-IN-ENDFOR
    Repeat the statements the number of times that there are characters in a string
  • Selection
    1. IF-THEN-ENDIF (execute the statements only if the Boolean expression is True)
    2. IF-THEN-ELSE-ENDIF (execute the statements following the THEN if the Boolean expression is True, otherwise execute the statements following the ELSE)
    3. NESTED IF-THEN-ELSE ENDIF (use nested versions of the above to create more complex conditions)
  • IF-THEN-ENDIF
    Execute the statements only if the Boolean expression is True
  • IF-THEN-ELSE-ENDIF
    Execute the statements following the THEN if the Boolean expression is True, otherwise execute the statements following the ELSE
  • NESTED IF-THEN-ELSE ENDIF
    Use nested versions of the above to create more complex conditions
  • IF (a MOD 4) = 2 THEN OUTPUT 'leaves a remainder of 2' ELSE OUTPUT 'leaves a remainder of 3' ENDIF
  • IF-THEN-ELSE IF ENDIF removes the need for multiple indentation levels
  • Assignment
    Identifier ← [Exp, … ,Exp]
  • primes
    • 2
    • 3
    • 5
    • 7
    • 11
    • 13
  • Accessing an element
    Identifier[IntExp]
  • Updating an element
    Identifier[IntExp] ← Exp
  • Accessing an element in a two-dimensional array
    Identifier[IntExp][IntExp]
  • table
    • [[1, 2],[2, 4],[3, 6],[4, 8]]
  • Array length
    LEN(Identifier)
  • FOR-IN-ENDFOR
    FOR Identifier IN array # statements here ENDFOR
  • Array items cannot be modified using FOR-IN-ENDFOR method
  • Record declaration
    RECORD Record_identifier field1 : <data type> field2 : <data type> … ENDRECORD
  • Car
    • make : String model : String reg : String price : Real noOfDoors : Integer
  • Variable Instantiation
    varName ← Record_identifier(value1, value2, …)
  • Assigning a value to a field in a record
    varName.fieldExp
  • Accessing values of fields within records
    varName.field
  • Subroutine definition
    SUBROUTINE Identifier(parameters) # statements here ENDSUBROUTINE
  • showAdd
    • a, b
  • Subroutines
    • Contain RETURN keyword are functions, those without are procedures