What is Pseudocode? | Advantages & Disadvantages | BCA | SparkEasy

 Pseudocode 

 

 

What is Pseudocode: Pseudocode is another program-planning tool used for planning program logic. “Pseudo” means imitation or false, and “Code” refers to the instructions written in a programming language.

 
pseudocode-indented-and-non-indented

 

Pseudocode, therefore, is an imitation of actual computer instructions. These pseudo instructions are phrases written in a natural language (e.g., English, French, German, etc.) that a computer cannot understand.

However, pseudocode uses a structure that resembles computer instructions. When a programmer uses pseudocode for planning a program, they can concentrate solely on developing the logic of the program without worrying about the syntax for writing program instructions because pseudocode does not have any syntax rules for formulating instructions.
 

Once a programmer is convinced that the program logic is sound, they can convert the pseudocode easily into a suitable programming language. Since the emphasis of pseudocode is on program design, it is also known as Program Design Language (PDL).

 

Pseudocodes for Basic Logic (Control) Structures


It is possible to express any program logic, no matter how complex, by using only the following three simple logic (control) structures: –

1. Sequence logic
2. Selection logic
3. Iteration (or looping) logic

If we structure programs using only these three logical structures, they are easier to understand because we can read them from top to bottom.

 
That is, by conceptualizing the logic of a program in the form of these three logical structures, programmers can avoid writing spaghetti (unstructured) code and produce programs that are easy to understand and maintain.
 

It also helps reduce programmer errors and the time spent in program testing. Writing of programs by using these three basic control structures is widely accepted and was termed the Structured Programming technique.

As good programming practices, programmers should develop program logic and write programs using the three basic logic structures.

 

Sequence Logic

 

sequence-logic-pseudocode

 

Sequence logic performs instructions one after another in sequence. Thus, for writing pseudocode instructions for sequence logic, we write the instructions in the order (or sequence) of their execution. The logic flow of pseudocode is from top to bottom.

 

Selection Logic


Selection logic, also known as decision logic, makes decisions. It selects a path out of two or more paths in program logic. We depict selection logic as an IF…THEN…ELSE, or an IF…THEN, or a CASE structure.

 

selection-logic-pseudocode-if-then-else
 
IF…THEN…ELSE structure means that if the condition is true, then do process 1; else (if the condition is not true), do process 2. Hence, program logic executes either Process 1 or Process 2 depending on whether the specified condition is true or false.
 
selection-logic-pseudocode-if-then
 
However, if we do not want to choose between two processes and want to decide whether to execute a process or not, then we use IF…THEN structure. IF…THEN structure means that if the condition is true, then do process 1; otherwise (if the condition is not true) skip over process 1.
 
selection-logic-pseudocode-case
 
CASE structure represents multiple-way selection logic. It allows choosing from more than two control paths in program logic, enabling selecting one of any number of statements or statement groups.
 
The CASE statement of the figure above indicates that if the value of Type is equal to Type-1, execute Process 1; if it is equal to Type-2, execute Process 2; if it is equal to Type-3, execute process 3, and so on.
 
In all these structures, Process 1, Process 2, Process 3, etc., can be one or more processes. They are not limited to a single process. In case of IF…THEN and IF…THEN…ELSE decision structures, ENDIF indicates their end; and in the case of CASE structure, ENDCASE marks its end.
 

Iteration (or Looping) Logic

 
Iteration logic produces a loop in program logic whenever the need to execute one or more instructions several times depending on some condition.
 
It uses two structures called DO…WHILE and REPEAT…UNTIL. Both DO…WHILE and REPEAT…UNTIL is used for looping. It is essential to know the difference between the two structures.
 

 

Iteration-logic-do-while

 

 
In DO…WHILE looping continues as long as the condition is true and stops when the condition is not true. Since program logic tests the condition for looping at the beginning of the loop, if the condition is false when it first encounters the loop, it will not execute the statements at all (not even once).
 

 

Iteration-logic-repeat-until

 

 
On the other hand, in REPEAT…UNTIL looping continues until the condition becomes true. That is, program logic repeats the execution of statements within the loop as long as the condition is not true. It tests the condition for looping at the end of the loop.
 
In both DO…WHILE and REPEAT…UNTIL the loop must contain a statement, which changes the condition that controls the loop. If it does not, looping will continue without end, becoming an infinite loop. Remember that no program should contain an infinite loop.
 
ENDDO marks the end of a DO…WHILE structure, and UNTIL followed by some condition marks the end of a REPEAT…UNTIL structure.
 

Indentation

 
One important feature of pseudocode as a program planning tool is indentation. Using indentation in pseudocode is the same technique used in various programming languages.
 
Its sole purpose is to represent the logical structure of a program with greater clarity. With this technique, we can quickly tell which program statements are part of which logic structure of the total program logic.
 

Advantages of Pseudocode

 
1. Compared to a flowchart, converting pseudocode to a programming language is much easier.
 
2. It is easier to modify the pseudocode of program logic when program modifications are necessary.
 
3. Writing pseudocode involves much less time and effort than drawing an equivalent flowchart.
 
Moreover, compared to writing a program in an actual programming language, pseudocode is easier to write because it has only a few rules to follow, allowing a programmer to concentrate on the logic of the program.
 

Disadvantages of Pseudocode

 
1. In the case of pseudocode, a graphic representation of program logic is not available.
 
2. There are no standard rules to follow in writing pseudo code. Different programmers use their style of writing pseudocode. Hence, communication problem occurs due to a lack of standardization.
 
3. Compared to flowcharts, beginners often find it more challenging to write pseudocode of program logic or follow a program’s logic from its pseudocode.
 
 

Leave a Comment