Professional Documents
Culture Documents
Pseudocode: General Rules
Pseudocode: General Rules
Pseudocode: General Rules
Please note that pseudocode can vary and the later examples do not strictly need to be
followed if you know what is right and wrong.
Output: S
General rules
• Do NOT EVER use a variable name in your pseudocode that you have not
previously defined or is not an input parameter.
• NEVER use a method in your pseudocode if you have not defined this method as
another algorithm. i.e. never use .length() or .append() unless you create an
algorithm and define them or explain what they do.
• Method names and variables names SHOULD NOT start with a capital letter.
• ALWAYS end your loops and if statements with an END FOR, END WHILE or
END IF.
Examples
Algorithm 1. backwards(inputArray)
Input: inputArray is of type integer array
1. end = |inputArray|-1
2. For i = end to i = 0
3. print inputArray[i]
4. i = i – 1
5. End For
Output:
__________________________________________________
Algorithm 2. backwards_with_output(inputArray)
Input: array is of type integer array
Output: array_two
___________________________________________________
Output:
___________________________________________________
Algorithm 4. untilTen(end)
Input: end is of type integer
1. i = 4
2. While i <= end
3. Print “Has not reached the end yet”
4. i = i + 1
5. End While
Output:
___________________________________________________
Algorithm 5. addToSet(originalList)
Input: originalList is of type list
1. newSet = ∅
2. For i = 0 to i = |originalList|
3. newSet = newSet ∪ originalList[i]
4. End For
Output: newSet
___________________________________________________
Output: setCallingMethod
Note how here we are calling another
method that we have defined earlier on.