What is pseudocode?
When you are just beginning to learn programming, there is a lot to learn before building your first application. To bridge the gap between what you want the application to do and the actual code to write, you can use pseudocode.
When you are just beginning to learn programming, there is a lot to learn before building your first application. Thinking as a programmer helps you break down problems into algorithms to solve them. Algorithms are the steps that your code will take to solve a problem or answer a question.
This can be challenging if you're just starting out. Turning ideas into actual code takes some practice.
To bridge the gap between what you want the application to do and the actual code to write, you can use pseudocode.
Learn about Pseudocode
- What is pseudocode?
- How useful is pseudocode?
- How to write pseudocode
- Condition
- Repetition
- Jaw
- Error handling
What is pseudocode?
Pseudocode is a plain text description of a piece of code or algorithm. It is not really programming, no scripts, no files and no programs. As the name implies, it is a 'pseudocode'.
Pseudocode is not written in any specific programming language. It is written in English and easy to understand.
Although pseudocode is not written in a programming language, there are still keywords used to refer to common concepts when writing code. They are written in capital letters for easier reading.
- START
- INPUT
- READ / GET
- PRINT / DISPLAY
- CALCULATE / DETERMINE
- SET
- INCREMENT / DECREMENT
- PROGRAM
- END
Here's a snippet of how pseudocode might look for a program that asks you to enter your favorite color and output your selection.
START PROGRAM getColor Create variable Color Ask the user for their favorite color READ INPUT into Color PRINT Color END
This is a fairly simple algorithm written in pseudocode. Anyone can read and understand what it is trying to accomplish.
As a programmer, all you have to do is bring it to life using whatever programming language you write code in. This is the same program in JavaScript:
let color = window.prompt("What is your favorite color?"); console.log(color);
This program uses JavaScript syntax to write algorithms. If you don't know JavaScript, it can be a little difficult to find out what's going on.
Pseudocode writes algorithms, programming languages that write syntax.
How useful is pseudocode?
Pseudocode helps you plan your application before writing. It helps you create algorithms that are easier to read than code syntax.
The JavaScript example is easy to read if you know this programming language. Specific terms like window.prompt or console.log don't reveal much about the algorithm.
If you interview to become a software engineer, the employer will not want you to remember the syntax. They will ask your knowledge about algorithms and structures. You will write much better code if you build your algorithms and structure before you start writing code.
How to write pseudocode
Writing a full program using pseudocode requires a lot of different commands and keywords just like regular programming. Please rely on keywords with pseudocode statements to build algorithms.
Condition
Conditional statements are very important in programming. These statements are IF statements or IF / ELSE statements, which can add logic to the code. These statements are written in pseudocode, using:
- IF
- ELSE
- ELSE IF
- THEN
Here, the program implements a simple IF / ELSE statement written in pseudocode. Let's see if you can determine what this code is trying to do just by reading it.
START PROGRAM isOdd Create variable Choice Ask the user for a number READ INPUT into Choice IF Choice is even THEN PRINT "No" ELSE PRINT "Yes" ENDIF END
It's a fairly simple program, asking users to give a number and do something depending on whether it is an odd or even number.
Repetition
Another essential part of programming is iteration, also known as loop creation. Some common loops are for and while . Both can be written in pseudocode.
START PROGRAM forLoop FOR 1 through 12 PRINT "Hello" ENDFOR END
This algorithm for a program will print 12 times the word 'Hello' . This shows how simple it is to write a loop in pseudocode.
While loops are also written very easily
START PROGRAM whileLoop Create variable Counter SET Counter equal to 1 WHILE Counter is less than 10 Print "Hello" INCREMENT Counter ENDWHILE END
Another fairly simple algorithm uses the while loop to print 'Hello'. Both loop examples have an explicit start and end to allow iteration.
You can also write do-while loops. The keywords in pseudocode will be REPEAT and UNTIL.
START PROGRAM doWhileLoop Create variable Counter SET Counter equal to 1 REPEAT Print "Hello" INCREMENT Counter UNTIL Counter is equal to 10 END
Like a do-while loop, this will perform an action until certain criteria are met. Once it is met, the loop will exit.
Jaw
Ham is the best programmer friend. They contain code that can be invoked and used in all high-level programming languages. Adding functions to pseudocode is easy.
START PROGRAM sampleFunction PRINT "This is a function" END
You can call functions in pseudocode.
call sampleFunction
The function is very simple and you can add any logic you like.
Error handling
Being able to write code that responds to bugs is very important when applications are developed. You can include this code in your pseudocode.
You can handle errors and exceptions by using keyword: EXCEPTION. Here, a simple algorithm will 'catch' the error
START PROGRAM catchError Create variable Number Ask the user for a number READ INPUT into Number EXCEPTION WHEN Number is not a number PRINT "Error: Please pick a number" END
Testing code is very important to writing good applications. Some of these exceptions will reappear in your tests, so it's good to write them in your pseudocode when planning your application.
You should read it
- How to Write Pseudocode
- How to Write Pseudocode
- How to Become a Computer Scientist
- How to Write Emotional Roleplaying Posts
- How to write curves in Photoshop
- Learn about Server role, Role service and Feature on Windows Server
- Learn about the Write Zero method
- Why write neat and organized HTML?
- How to enable / disable Disk Write Caching in Windows 10
- Henry Cavill officially dropped the role of Superman, DC will also give up everything to start again
- What is JD? What does JD mean?
- How to install DNS Role in Windows Server 2012
Maybe you are interested
What is Miracast Connect? On which device? Instructions on how to use Miracast Three sets of skeletons reveal the tragic history of the first African people to reach America The diseases of computer addicts Internet Explorer 9 Platform Preview 7 reasons ultrabook can create technology revolution 'Super ultrabook' will appear at CES 2012