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/ 6
Pseudocode
What is Algorithm An algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example,
An algorithm to add two numbers:
1. Take two number inputs
2. Add numbers using the + operator 3. Display the result What is Pseudocode Pseudocode is a way of writing or describing programming code or algorithms in a natural language such as English. Pseudocode cannot be compiled nor executed as it is only meant to be read by humans. It is also known as 'false code' or 'representation of code.' Pseudocode is often used to plan out a program or algorithm in detail before it is written in a specific programming language. One of the important considerations when writing pseudocode is to write only one statement per line. Other guidelines include using easy- to-understand language, avoiding ambiguity, and using indentations to improve readability. An example of well-written pseudocode would be the following lines which compute the area of a triangle: Enter base length, B | Enter height, H | Calculate the area = 1/2 * B * H | Display area. Why is Pseudocode Useful There are several advantages to using pseudocode including that it is easy to modify, can be easily written in a word processing application, and can be used with structured programming languages. One thing that some may not consider a direct advantage is that there is no standardized version of pseudocode. The writer chooses whichever method works for them.It is also used for creating an outline or a rough draft of a program.Pseudocode helps you plan out your app before you write it Examples of Pseudocode Statements IF Statement : An IF statement starts with a condition which is tested. If the condition evaluates as TRUE then the THEN code block will be run. If the condition evaluates as false then the ELSE block will run. In the following example "Hello" will be printed if x = 1, otherwise "Good night" will be printed. While Statement : In this case, we could use a while loop to determine that answer: The "pseudocode" for such an algorithm is: while the number is bigger than one keep dividing it by two. additionally, keep a count of how many times we do the division. Examples of Pseudocode Statements Repeat Statement : A REPEAT loop will repeat the code block until the given condition is true. The condition is not checked until after the code has run once, so regardless of whether the condition is true or not the code will always run at least once.