[go: up one dir, main page]

100% found this document useful (1 vote)
286 views30 pages

Pseudocode and Flowcharts

The document provides information on pseudocode, flowcharts, and common programming structures like conditional statements and loops. It defines key terms like algorithms, programming languages, and pseudocode. It also describes common pseudocode notations and provides examples of how to write pseudocode using selection, repetition, and other structures.

Uploaded by

Bryan Mendoza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
286 views30 pages

Pseudocode and Flowcharts

The document provides information on pseudocode, flowcharts, and common programming structures like conditional statements and loops. It defines key terms like algorithms, programming languages, and pseudocode. It also describes common pseudocode notations and provides examples of how to write pseudocode using selection, repetition, and other structures.

Uploaded by

Bryan Mendoza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

PSEUDOCODE AND

FLOWCHARTS
CONDITIONAL STATEMENTS, PSEUDOCODE AND LOOPING
STRUCTURES.
REVISION
DEFINE….

• Algorithm- An algorithm is a plan, a logical step-by-step process for solving a problem.


Algorithms are normally written as a flowchart or in pseudocode.
A sequence of logical instructions for carrying out a task. In computing,
algorithms are needed to design computer programs.
• Program- Sequences of instructions for a computer.
• Programming language- A language used by a programmer to write a piece of software.
There are many programming languages.
• Pseudocode- A method of writing up a set of instructions for a computer program using
plain English. This is a good way of planning a program before coding.
DEFINE….

• Condition- In computing, this is a statement or sum that is either true or false.


A computation depends on whether a condition equates to true or false.
• Flowchart- A diagram that shows a process, made up of boxes representing
steps, decision, inputs and outputs.
• Loop- A method used in programming to repeat a set of instructions.
• Pseudocode- A method of writing up a set of instructions for a computer
program using plain English. This is a good way of planning a program before
coding.
PSEUDOCODE

Most programs are developed using programming languages. These


languages have specific syntax that must be used so that the program will run
properly. Pseudocode is not a programming language, it is a simple way of
describing a set of instructions that does not have to use specific syntax. It
does not follow strict rules and style of any particular programming language.
Pseudocode is used for learning programming concepts and to describe ideas
before coding begins.
INSTRUCTIONS TO WRITE A PSEUDOCODE

There are 3 programming/pseudocode constructs:


1. Sequence: It refers that instructions should be executed one after another.
2. Selection: This construct is used to make a decision in choosing an option from many
available options on the basis of a condition. So, if a condition is true then one option
would be chosen while if a condition is false then another option will be chosen.
3. Repetition: This construct is used to repeat a block of code as per the given condition.
COMMON PSEUDOCODE NOTATION
• There is no strict set of standard notations for pseudocode, but some of the most
widely recognized are:
• INPUT – indicates a user will be inputting something
• OUTPUT – indicates that an output will appear on the screen
• WHILE – a loop (iteration that has a condition at the beginning)
• FOR – a counting loop (iteration)
• REPEAT – UNTIL – a loop (iteration) that has a condition at the end
• IF – THEN – ELSE – a decision (selection) in which a choice is made
• any instructions that occur inside a selection or iteration are usually indented
USING
PSEUDOCODE
Pseudocode can be used
to plan out programs.
Planning a program that
asks people what the
best subject they take is,
would look like this in
pseudocode:
ASSIGNMENT

• In order to change the data value stored in a variable, you use an operation


called assignment. This causes the value to be copied into a 
memory location, overwriting what was in there before.
• Different values may be assigned to a variable at different times during the 
execution of a program. Each assignment overwrites the current value with a
new one.
ASSIGNMENT OPERATOR
BASIC
MATHEMATICAL
OPERATORS
CONDITIONAL STATEMENTS

IF … THEN... ELSE… ENDIF: The


selection statement is used when we want
to perform one operation when a condition
is true and another operation when a
condition is false, or another condition is
true. It is used to choose a route from all
available routes in an
algorithm/pseudocode.
STRUCTURE
OPERATORS
COMPLETE
ANSWER
DETAILED ALGORITHM
CASE…OF…OTHERWISE…ENDCASE

When there are too many available routes in an algorithm/pseudocode then it


requires too many IF … THEN … ELSE … ENDIF statements to make a selection
among these routes which is not an easy task and it makes pseudocode difficult to
manage. To overcome this issue CASE … OF … OTHERWISE Statement is used.
In short, CASE … OF … OTHERWISE … ENDCASE is used in place of IF …
THEN … ELSE… ENDIF statement when we have to make a selection of a route
from too many available routes.
COMPLETE

Write down pseudocode that will take a number as input (from 1 to 7) and print
the day name for corresponding number example 1 for Monday 2 for Tuesday
and so on.
SOLUTION
LOOP STRUCTURES

• There are three types of repetition statements:


• 1. FOR … TO …. NEXT
• 2. WHILE… DO …. ENDWHILE
• 3. REPEAT … UNTIL
FOR… TO … NEXT
This repetition statement is used when we know how many times an instruction or set of
instructions is to be repeated.
Few things to remember about FOR…TO…NEXT loop are:
There is a variable in FOR … TO … NEXT loop for controlling the number of iterations and is
known as a control variable. The name of the control variable is usually ‘Count’.
We specify the initial (lower) and final (higher) values of the control variable in the opening
statement of the loop. These initial and final values are not restricted to the numerical values
only, they can be variables as well.
The Control Variable is automatically incremented by ‘1’ each time the loop ends.
The value of the control variable is tested at the beginning of the loop & loop is repeated until
the value of control variable is less than or equal to the specified final value.
LOOP STRUCTURES

Example 4: Write pseudocode that will take 10 numbers as input and print their
average by using FOR…TO…NEXT loop.
SOLUTION
WHILE … DO … ENDWHILE
This repetition statement is used when we don’t know how many times an
instruction or set of instructions is to be repeated.
Few things to remember about WHILE…DO…ENDWHILE loop are:
The loop is repeated until a condition is true and halted when the condition is false.
Condition is tested at the beginning of the loop.
The statements/instruction between DO and ENDWHILE keywords are repeated.
LOOP STRUCTURES

Write pseudocode that will take numbers input and add them while the input
number is greater than or equal to 0. Print the final result using WHILE…
DO…ENDWHILE.
SOLUTION
REPEAT … UNTIL

It is a repetition statement that is used when we don’t know how many times an
instruction or set of instructions is to be repeated.
It is different from WHILE… DO … ENDWHILE because this loop will be
repeated until a condition is false and it will stop executing once the condition
is true.
The condition is tested at the end of the loop and even if a condition is true the
loop will execute at least once.
LOOP STRUCTURE

Write the pseudocode that will take numbers as input, add and gives the total as
output. The loop will continue until “0” is given as input. Use REPEAT…
UNTIL.
SOLUTION
Thank You!

You might also like