Pseudocode

After studying this section you should be able to describe algorithms using pseudocode

Constructing an algorithm

An algorithm is a sequence of instructions to solve a given problem. There are many different ways of expressing algorithms but an excellent method is to use pseudocode. Pseudocode is a name given to a formal method of writing down the steps involved in an algorithm and is close to the final program code. It has all the constructs that you might expect in a program language. Typical pseudocode constructs include:

• PROCEDURE … ENDPROC

• FUNCTION … ENDFUN

• IF … THEN … ELSE … ENDIF

• WHILE … DO … ENDWHILE

• REPEAT … UNTIL

• FOR … TO … ENDFOR

• CASE … OF … ENDCASE

Some writers use upper case for the constructs and lower case for the rest of the algorithm but it is not a fixed rule.

Most pseudocode will use the above constructs but there are no fixed rules about pseudocode and you may see other approaches. The nice thing about pseudocode is that you can largely ignore syntax rules as long as the code makes sense. The line of Pascal code

X := 6;

can be written in pseudocode as:

X := 6

Set X to be 6

X ← 6

Put 6 in X

or any other statement that means the same. In the same way, we do not worry about declaring variables, and if you are not sure how to do something simply write in English what it is you hope to achieve.

Category
ULAW Banner
Register Now
Slot