Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

A computer program is  a sequence of machine language instructions, expressing a meaningful sequence of statements possessing an order of execution and specifying a computer representation of an algorithm process.

An algorithm is a list of instructions specifying a sequence of operations  which will give the answer to any problem of a given type.  Generally speaking, an algorithm is a sequence of steps leading to the solution of a given problem or it is a step-by-step method of solving a problem or doing a task;  however, one feature distinguishes it from an ordinary procedure or list of instructions. The distinguishing feature is that an algorithm is designed to operate on data that are not known beforehand. In fact, the input of data may be a part of the algorithm itself. It is a single list of instructions defining a calculation which may be carried out on any initial data and which, in each case, gives the correct result. In other words, an algorithm tells how to solve not just one particular problem, but a whole class of similar problems.

* Algorithms can be expressed in several kinds of notation like; Pseudo Code, Flowcharts, Natural Language and Programming Language.  

Pseudocode  and Flowchart 

When programmers plan the logic for a solution to a programming problem, they often use one of two tools, pseudocode (“sue-doe-code”) or flowcharts.  Pseudocode is an English-like representation of the logical steps it takes to solve a problem.   A flowchart is a pictorial representation of the same thing.  

The old cliche, "a picture is worth a thousand words," has particular  truth for the person preparing a program for computer processing or designing a data processing system that uses a computer for one or more of its functions. A  flow chart is a picture of the steps which must be performed to accomplish a given job; it is useful during the planning stage and serves as a guideline for implementation as well. A flow chart is also an important part of the documentation of a program or system.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.


Pseudo is a prefix that means “false,” and to code a program means to put it in a programming language; therefore, pseudocode simply means “false code,” or statements that appear to have been written in a computer programming language but do not necessarily follow any syntax rules of any specific language. Another name for pseudocode is Programming Design Language (PDL).

Pseudocode is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled natural language without any syntax rules  and can easily be converted into real programming language statements. Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language intended for human reading only. 

The purpose of using pseudocode is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and scientific publications that are documenting various algorithms, and for sketching out the structure of the program before the actual coding takes place.

PseudoCode must be complete in describing the logic of the algorithm so that it will be an easy task of translating it line-by-line in to its equivalent Source Code (Program Coding).

The following five statements constitute a pseudo code  representation of a number-doubling problem: 

start 
    input myNumber 
    set myAnswer = myNumber * 2 
    output myAnswer 
Stop


Pseudocode is fairly flexible because it is a planning tool, and not the final product. Therefore, From the example above , you might prefer any of the following: 

  • Instead of start and stop, some pseudocode developers would use other terms such as begin and end
  • Instead of writing input myNumber, some developers would write get myNumber or read myNumber. 
  • Instead of writing set myAnswer = myNumber * 2, some developers would write calculate myAnswer = myNumber times 2 or compute myAnswer as myNumber doubled. 
  • Instead of writing output myAnswer, many pseudocode developers would write display myAnswer, print myAnswer, or write myAnswer. 

Common Action Keywords
are often used to indicate common input, output, and processing operations. 

Input: READ, OBTAIN, GET
Output: PRINT, WRITE, DISPLAY, SHOW
Compute: COMPUTE, CALCULATE, DETERMINE
Initialize: SET, INIT
Add one: INCREMENT, BUMP,INCREASE

Another example is to find the perimeter and area of a rectangle. To find the perimeter and area of a rectangle, you need to know the rectangle’s length and width.

The perimeter and area of the rectangle are then given by the following formulas:

perimeter = 2 * (length + width)
area = length * width

The pseudocode to find the perimeter and area of the rectangle is as follows:

Begin

Get the length of the rectangle.

Get the width of the rectangle.

Compute perimeter = 2 *  (length + width)

Compute area = length * width

End 


Each textbook and each individual designer may have their own personal style of pseudocode. Pseudocode is not a rigorous notation, since it is read by other people, not by the computer. There is no universal "standard" for the industry, but for instructional purposes it is helpful if we all follow a similar style. The format below is recommended for expressing your solutions in our class.

The "structured" part of pseudocode is a notation for representing six specific structured programming constructs:

    1. SEQUENCE
    2. WHILE
    3. IF-THEN-ELSE
    4. REPEAT-UNTIL
    5. FOR
    6. CASE. 

Each of these constructs can be embedded inside any other construct. These constructs represent the logic, or flow of control in an algorithm. For writing any computer program, it has been proven to be sufficient, that Pseudo Code is made up of the following Logic Structures.

1-Sequence Logic

2-Selection or Decision Logic 

3-Iteration or Repetition Logic

1-Sequence Logic 

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

2-Selection or Decision Logic 

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

3-Iteration or Repetition Logic.

  1. Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

These three basic constructs for flow of control are sufficient to implement any "proper" algorithm.

1- SEQUENCE LOGIC is a linear progression where one task is performed sequentially after another. The instructions are written in an order in which they are performed. The logic flow is from top to bottom.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

EXAMPLE: Get the Area of a Rectangle.

Begin

    READ height of rectangle 
    READ width of rectangle               or  ( READ height and width of rectangle )
    COMPUTE area as height times width        

    Display the area computed

End

2- SELECTION LOGIC is a Decision Logic for making decision or selection in which a proper choice is made between two or more alternative courses of action. Selection Logic is depicted as  IF ... THEN ... ELSE,  IF ... THEN  or a CASE constructs. 

If the condition is true, 

     Then  sequence 1 (process 1) is performed, 

Else  sequence 2 (process 2) is performed.  

IF ... THEN  Construct

IF condition THEN

    sequence 1 (process 1)

ELSE

    sequence 2 (process 2)

ENDIF

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Example: Compute Salary and Overtime
    IF HoursWorked > Normal THEN
        Compute Regular Salary with overtime
    ELSE
        Compute Regular Salary 
    ENDIF

The ELSE keyword and "sequence 2" are optional. 

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.


Example: Compute the number of Male Students
  IF Student is a Male THEN
        Increase  MaleCount by 1

  ENDIF

There are times we may need to test several or multiple conditions and perform a specific task or process for each corresponding conditions as shown from the flowchart below.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

 CASE construct indicates a multiway branch based on conditions that are mutually exclusive. The Four keywords ( CASE, OF, OTHERS, and ENDCASE ) and conditions are used to indicate the various alternatives. The general form is:

CASE expression OF

condition 1 : sequence 1 

condition 2 : sequence 2

...

condition n : sequence n

OTHERS:  default sequence

ENDCASE

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

The OTHERS clause with its default sequence is optional. Conditions are normally numbers or characters indicating the value of "expression", but they can be English statements or some other notation that specifies the condition under which the given sequence is to be performed. A certain sequence may be associated with more than one condition.

Example 1

        CASE  Title  OF
                Mr       : Print "Mister"
                Mrs     : Print "Missus"
                Miss    : Print "Miss"
                Ms       : Print "Mizz"
                Dr        : Print "Doctor"
        ENDCASE

Example 2

        CASE  grade  OF
                 100 > X > 89:  points = 4
                   90 > X > 79:  points = 3
                   80 > X > 69:  points = 2
                   70 >  X > 59:  points = 1
                              X < 60:  points = 0
        ENDCASE

3- ITERATION LOGIC or REPETITION  is used to produce LOOPs where one or more instructions may be executed repeatedly several times depending on some of the conditions. It uses the structures of the WHILE,  FOR and the REPEAT-UNTIL constructs.

WHILE condition

    sequence

ENDWHILE

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

The loop is entered only if the condition is true.  The "sequence" is performed for each iteration. At the conclusion of each iteration, the condition is evaluated and the loop continues as long as the condition is true, else at false condition, the next execution is branch out of the loop.

Example-1
Get the product of the first 10 natural numbers.

Begin

SET  n = 1 , prod = 1, Limit = 10

WHILE  n < Limit

    Compute prod = prod * n

     Incrment n by 1

ENDWHILE

End

Example-2
Count up: Read an integer number n and print the integers counting up from 1 to n

Start

Read n

Initialize .i to 1.

While i <= n, do;

Write i,

Increment . i 

end while

Stop.

FOR LOOP
This loop is a specialized construct for iterating a specific number of times, often called a "counting" loop. Two keywords, FOR and ENDFOR are used. The general form is:

FOR (

iteration bounds)
    sequence

ENDFOR

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.


Example:  

Find the product of the first 10 Natural Numbers.

Begin

        set prod = 1

FOR (n = 1 to 10)

prod = prod * n

ENDFOR

Display prod

End

REPEAT-UNTIL Loop
This loop is similar to the WHILE loop except that the test is performed at the bottom of the loop instead of at the top. Two keywords, REPEAT and UNTIL are used. The general form is:

REPEAT
    sequence (process 1 ... n)
UNTIL condition

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

Pseudocode is an english-like representation of the logical steps necessary to solve a problem.

The "sequence" in this type of loop is always performed at least once, because the test is peformed after the sequence is executed. At the conclusion of each iteration, the condition is evaluated, and the loop repeats if the condition is false. The loop terminates when the condition becomes true. 

Example:  

Find the product of the first 10 Natural Numbers.

Begin

What is an English like representation of the logical steps it takes to solve a problem?

Essentially, a flowchart is a pictorial representation of a step-by-step solution to a problem. It consists of arrows representing the direction the program takes and boxes and other symbols representing actions.

What is an English like representation of logic?

A flowchart is an English-like representation of the logical steps necessary to solve a problem. T. An infinite loop is a flow of program logic that repeats and never ends.

How pseudocode is used as a problem solving tool?

Pseudocode is a great method for uncovering unclear decisions, hidden side effects, and for defining all inputs, outputs and interactions needed to effectively solve a problem. The art of successfully executing great ideas involves becoming better at problem solving, listening & communicating.

What is a pseudocode in programming?

Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented.