PSEUDOCODE - HAGGIS
What is HAGGIS?
•

Haggis is very similar to programming language in which it has strictly defined
syntax and rules.
Formatting of HAGGIS
Keywords
Are all captitalised. For example SET, FOR, WHILE etc
1.

2. Line Numbers
Lines should be numbered as shown below using a capital L and a single space before each
number. This makes it easier to refer to certain parts of the pseudocode.
Line 1
Line 2
Line 3
A refinement of Line 1 would be shown as:
Line 1.1
Line 1.2
Formatting Cont.
3.

Indentation

The beginning and the end of some constructs should be highlighted by indenting the code inbetween
Line 1 REPEAT
Line 2
SET total = total + 5
Line 3 UNTIL total = 100
4.

Variable names

Simple variable names that use only one word should be written in lower case.
total
name
Any variables using more than one word should use capital letters. For example:

totalScore
firstName
Formatting Cont.
5. Data
If the data used is numeric then should be wrote on it’s own.
SET number TO 932
If the data is text then it is indicated by using “ ”.
SET name TO “bob”
What does it look like?
Variables / Arrays
If the Variable is set within the program, the command words SET & TO are used to assign values
to variables and Arrays.

Numeric:
SET number TO 973
String:
SET name TO “bob”
Array:
SET names[3] TO “John”
SET names[loop] TO “Jess”
What does it look like?
Variable and Arrays Cont.
If variables have been assigned a value as part of an input system. i.e. user has typed in
their name and stored in the variable name. Then the command used is RECEIVE & FROM

What device
is used to
input:

Variable
name
RECEIVE name FROM (string) KEYBOARD

Variable
type:
String
Integer
Real
Boolean

Keyboard
Mouse
Sensor
Touchscreen
Web Cam
Microphone
What does it look like?
Outputting Data
Numeric

SEND 23 TO DISPLAY

Variable

SEND total TO DISPLAY

String

SEND “The total is:” TO DISPLAY

Alternative

SEND “Print this Text” TO PRINTER
What does it look like?
Arithmetic Operators

Arithmetic operators are normally used with a SET or SEND

SET number TO 911+ 34
SET number TO 34/7
SEND 34*78 TO DISPLAY
SET total TO num1 + num2
What does it look like?
Expressions to Concatenate Strings
Text, number & variables may be concatenated with an ampersand (&) and enclosed by [ ]:
SET errorMessage TO [“Device failed due to fault number” & faultNumber]
SEND [“Player” & playerNumber & “’s score is” & playerScore] TO DISPLAY
What does it look like?
Conditions and logical operators

The command IF and THEN are used to make decisions
An IF statement with a simple condition can take two forms:

Single Line

IF temperatureNow>= 100 THEN SEND “Water is in a gaseous form at this temp” TO DISPLAY
Extended statement
IF temperatureNow >= 100 THEN
SEND “Water is in a gaseous form at this temp” TO DISPLAY
SEND “This is called steam” TO DISPLAY
ELSE
SEND “Water is a liquid or solid at this temp” TO DISPLAY

END IF
What does it look like?
Complex Conditions

Use of (AND, OR, NOT)
IF temperatureNow > 0 AND temperatureNow <100 THEN

SEND “Water is a liquid at this temp” TO DISPLAY
What does it look like?
Fixed loops
Code may be repeated a fixed number of times using FOR, FROM, TO, DO, END FOR.

FOR counter FROM 1 TO 10 DO
GET nextInput FROM (Real) Keyboard
SET totalCostTO totalCost + nextInput
END FOR
Alternatively, a fixed loop may also be written using the REPEAT, TIMES, END REPEAT commands:

REPEAT 10 TIMES
RECEIVED nextValue FROM (REAL) KEYBOARD
END REPEAT
What does it look like?
Conditional Loops
Loops may also be ended with a pre or post condition using WHILE, END WHILE or
REPEATE

Pre Condition
RECEIVE password FROM (STRING) KEYBOARD
WHILE password = “ “ DO
IF password = “Pass” THEN
SEND “Correct Password” TO DISPLAY
END IF
END WHILE
Post condition
REPEAT
RECEIVE password FROM (STRING) KEYBOARD
IF password = “Pass” THEN
SEND “Correct Password” TO DISPLAY
END IF
UNTIL password = “Pass”

Pseudocode haggis

  • 1.
  • 2.
    What is HAGGIS? • Haggisis very similar to programming language in which it has strictly defined syntax and rules.
  • 3.
    Formatting of HAGGIS Keywords Areall captitalised. For example SET, FOR, WHILE etc 1. 2. Line Numbers Lines should be numbered as shown below using a capital L and a single space before each number. This makes it easier to refer to certain parts of the pseudocode. Line 1 Line 2 Line 3 A refinement of Line 1 would be shown as: Line 1.1 Line 1.2
  • 4.
    Formatting Cont. 3. Indentation The beginningand the end of some constructs should be highlighted by indenting the code inbetween Line 1 REPEAT Line 2 SET total = total + 5 Line 3 UNTIL total = 100 4. Variable names Simple variable names that use only one word should be written in lower case. total name Any variables using more than one word should use capital letters. For example: totalScore firstName
  • 5.
    Formatting Cont. 5. Data Ifthe data used is numeric then should be wrote on it’s own. SET number TO 932 If the data is text then it is indicated by using “ ”. SET name TO “bob”
  • 6.
    What does itlook like? Variables / Arrays If the Variable is set within the program, the command words SET & TO are used to assign values to variables and Arrays. Numeric: SET number TO 973 String: SET name TO “bob” Array: SET names[3] TO “John” SET names[loop] TO “Jess”
  • 7.
    What does itlook like? Variable and Arrays Cont. If variables have been assigned a value as part of an input system. i.e. user has typed in their name and stored in the variable name. Then the command used is RECEIVE & FROM What device is used to input: Variable name RECEIVE name FROM (string) KEYBOARD Variable type: String Integer Real Boolean Keyboard Mouse Sensor Touchscreen Web Cam Microphone
  • 8.
    What does itlook like? Outputting Data Numeric SEND 23 TO DISPLAY Variable SEND total TO DISPLAY String SEND “The total is:” TO DISPLAY Alternative SEND “Print this Text” TO PRINTER
  • 9.
    What does itlook like? Arithmetic Operators Arithmetic operators are normally used with a SET or SEND SET number TO 911+ 34 SET number TO 34/7 SEND 34*78 TO DISPLAY SET total TO num1 + num2
  • 10.
    What does itlook like? Expressions to Concatenate Strings Text, number & variables may be concatenated with an ampersand (&) and enclosed by [ ]: SET errorMessage TO [“Device failed due to fault number” & faultNumber] SEND [“Player” & playerNumber & “’s score is” & playerScore] TO DISPLAY
  • 11.
    What does itlook like? Conditions and logical operators The command IF and THEN are used to make decisions An IF statement with a simple condition can take two forms: Single Line IF temperatureNow>= 100 THEN SEND “Water is in a gaseous form at this temp” TO DISPLAY
  • 12.
    Extended statement IF temperatureNow>= 100 THEN SEND “Water is in a gaseous form at this temp” TO DISPLAY SEND “This is called steam” TO DISPLAY ELSE SEND “Water is a liquid or solid at this temp” TO DISPLAY END IF
  • 13.
    What does itlook like? Complex Conditions Use of (AND, OR, NOT) IF temperatureNow > 0 AND temperatureNow <100 THEN SEND “Water is a liquid at this temp” TO DISPLAY
  • 14.
    What does itlook like? Fixed loops Code may be repeated a fixed number of times using FOR, FROM, TO, DO, END FOR. FOR counter FROM 1 TO 10 DO GET nextInput FROM (Real) Keyboard SET totalCostTO totalCost + nextInput END FOR Alternatively, a fixed loop may also be written using the REPEAT, TIMES, END REPEAT commands: REPEAT 10 TIMES RECEIVED nextValue FROM (REAL) KEYBOARD END REPEAT
  • 15.
    What does itlook like? Conditional Loops Loops may also be ended with a pre or post condition using WHILE, END WHILE or REPEATE Pre Condition RECEIVE password FROM (STRING) KEYBOARD WHILE password = “ “ DO IF password = “Pass” THEN SEND “Correct Password” TO DISPLAY END IF END WHILE
  • 16.
    Post condition REPEAT RECEIVE passwordFROM (STRING) KEYBOARD IF password = “Pass” THEN SEND “Correct Password” TO DISPLAY END IF UNTIL password = “Pass”