Writing pseudo-code
Pseudo-code
Pseudo-code is a cross between English and the keywords used in programming languages. It also makes use of the programming constructs found in programming languages (sequence, selection, iteration) but it has no strict rules that you have to follow. It is used to effectively describe solutions in a near-programming language type of way! This means that the pseudo-code can then be given to a programmer expert in any language and they should be able to quickly convert the pseudo-code into that language. This is the big advantage of pseudo-code. It is independent of any particular programming language and can be quickly converted into any language!
An example of pseudo-code
Suppose you need to write an algorithm to find a record in a file. A first attempt at an algorithm might look like this (Don’t worry if you don’t understand the code. We are only at the beginning of a long path)!
RecordFound=FALSE
EndOfFile=FALSE
READ Key field of record you want to find
READ First record in file
WHILE ((EndOFFile=FALSE) AND (RecordFound=FALSE)) DO
BEGIN
COMPARE record you are looking for with record from file
IF same THEN
RecordFound=TRUE
PRINT "Record found"
ELSE
IF EndOfFile Then
EndOfFile=TRUE
PRINT "End of file reached. Record not found."
ELSE
READ next record
ENDIF
ENDIF
END
ENDWHILE