Pseudo code is a
step-by-step verbal outline of your code that you can gradually transcribe into
programming language. Many programmers use it to plan out the function of an
algorithm before setting themselves to the more technical task of coding.
Pseudo code serves as an informal guide, a tool for thinking through program
In general the vocabulary used in the pseudo code
should be the vocabulary of the problem domain, not of the implementation
domain. The pseudo code is a narrative for someone who knows the
requirements (problem domain) and is trying to learn how the solution is
organized.
NB:- logic must be decomposed to the level of a
single loop or decision.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:
SEQUENCE, WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and CASE. Each of these
constructs can be embedded inside any other construct. These construct
represent the logic, or flow of control in an algorithm.
It has been proven that three basic constructs for
flow of control are sufficient to implement any "proper" algorithm.
SEQUENCE is a
linear progression where one task is performed sequentially after another.
It has been proven that three basic constructs for
flow of control are sufficient to implement any "proper" algorithm.
SEQUENCE is a
linear progression where one task is performed sequentially after another.
WHILE is a loop (repetition) with a simple conditional test at its beginning.
IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action.Although these constructs are sufficient, it is often useful to include three more constructs:
WHILE is a loop (repetition) with a simple conditional test at its beginning.
IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action.Although these constructs are sufficient, it is often useful to include three more constructs:
CASE is a
multiway branch (decision) based on the value of an expression. CASE is a
generalization of IF-THEN-ELSE.
FOR is a "counting" loop.
FOR is a "counting" loop.
SEQUENCE
Sequential control is indicated by writing one
action after another, each action on a line by itself, and all actions aligned
with the same indent. The actions are performed in the sequence (top to bottom)
that they are written.
IF-THEN-ELSE
Binary choice on a given Boolean condition is
indicated by the use of four keywords: IF, THEN, ELSE, and ENDIF. The general
form is:
IF condition THEN
sequence 1
ELSE
sequence 2
ENDIF
The ELSE keyword and "sequence 2" are
optional. If the condition is true, sequence 1 is performed, otherwise sequence
2 is performed.
Example
IF HoursWorked > NormalMax THEN
Display overtime message
ELSE
Display regular time message
ENDIF
WHILE
The WHILE construct is used to specify a loop with
a test at the top. The beginning and ending of the loop are indicated by two
keywords WHILE and ENDWHILE. The general form is:
WHILE condition
Sequence
ENDWHILE
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.
Example
WHILE Population < Limit
Compute Population as Population + Births - Deaths
ENDWHILE
Example
WHILE employee. type NOT EQUAL manager AND
personCount < numEmployees
INCREMENT personCount
CALL employeeList.getPerson with personCount RETURNING employee
CALL employeeList.getPerson with personCount RETURNING employee
ENDWHILE
CASE
A CASE construct indicates a multiway branch based
on conditions that are mutually exclusive. 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
condition 2 : sequence 2
...
condition n : sequence n
OTHERS:
default sequence
ENDCASE
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
FOR X = 1 to 10
FOR Y = 1 to 10
IF game Board[X][Y] = 0
Do nothing
ELSE
CALL the Call(X, Y) (recursive method)
increment counter
END IF
END FOR
END FO
FOR Y = 1 to 10
IF game Board[X][Y] = 0
Do nothing
ELSE
CALL the Call(X, Y) (recursive method)
increment counter
END IF
END FOR
END FO
Pseudo code is a
step-by-step verbal outline of your code that you can gradually transcribe into
programming language. Many programmers use it to plan out the function of an
algorithm before setting themselves to the more technical task of coding.
Pseudo code serves as an informal guide, a tool for thinking through program
In general the vocabulary used in the pseudo code
should be the vocabulary of the problem domain, not of the implementation
domain. The pseudo code is a narrative for someone who knows the
requirements (problem domain) and is trying to learn how the solution is
organized.
NB:- logic must be decomposed to the level of a
single loop or decision.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:
SEQUENCE, WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and CASE. Each of these
constructs can be embedded inside any other construct. These construct
represent the logic, or flow of control in an algorithm.
It has been proven that three basic constructs for
flow of control are sufficient to implement any "proper" algorithm.
SEQUENCE is a
linear progression where one task is performed sequentially after another.
It has been proven that three basic constructs for
flow of control are sufficient to implement any "proper" algorithm.
SEQUENCE is a
linear progression where one task is performed sequentially after another.
WHILE is a loop (repetition) with a simple conditional test at its beginning.
IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action.Although these constructs are sufficient, it is often useful to include three more constructs:
WHILE is a loop (repetition) with a simple conditional test at its beginning.
IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action.Although these constructs are sufficient, it is often useful to include three more constructs:
CASE is a
multiway branch (decision) based on the value of an expression. CASE is a
generalization of IF-THEN-ELSE.
FOR is a "counting" loop.
FOR is a "counting" loop.
SEQUENCE
Sequential control is indicated by writing one
action after another, each action on a line by itself, and all actions aligned
with the same indent. The actions are performed in the sequence (top to bottom)
that they are written.
IF-THEN-ELSE
Binary choice on a given Boolean condition is
indicated by the use of four keywords: IF, THEN, ELSE, and ENDIF. The general
form is:
IF condition THEN
sequence 1
ELSE
sequence 2
ENDIF
The ELSE keyword and "sequence 2" are
optional. If the condition is true, sequence 1 is performed, otherwise sequence
2 is performed.
Example
IF HoursWorked > NormalMax THEN
Display overtime message
ELSE
Display regular time message
ENDIF
WHILE
The WHILE construct is used to specify a loop with
a test at the top. The beginning and ending of the loop are indicated by two
keywords WHILE and ENDWHILE. The general form is:
WHILE condition
Sequence
ENDWHILE
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.
Example
WHILE Population < Limit
Compute Population as Population + Births - Deaths
ENDWHILE
Example
WHILE employee. type NOT EQUAL manager AND
personCount < numEmployees
INCREMENT personCount
CALL employeeList.getPerson with personCount RETURNING employee
CALL employeeList.getPerson with personCount RETURNING employee
ENDWHILE
CASE
A CASE construct indicates a multiway branch based
on conditions that are mutually exclusive. 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
condition 2 : sequence 2
...
condition n : sequence n
OTHERS:
default sequence
ENDCASE
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
FOR X = 1 to 10
FOR Y = 1 to 10
IF game Board[X][Y] = 0
Do nothing
ELSE
CALL the Call(X, Y) (recursive method)
increment counter
END IF
END FOR
END FOR
FOR Y = 1 to 10
IF game Board[X][Y] = 0
Do nothing
ELSE
CALL the Call(X, Y) (recursive method)
increment counter
END IF
END FOR
END FOR





