How to Write Pseudocode
Master the fundamentals of pseudocode
Know what pseudocode is. Pseudocode is a step-by-step code outline that you can gradually convert into a programming language. Many programmers use pseudocode to plan out an algorithm's functions before setting them up as more technical coding tasks.
Pseudocode serves as an unofficial guide, as an aid in brainstorming solutions to program problems, and as a communication tool that can help you present your ideas. with others.
Understand why pseudocode is useful. Pseudocode is used to illustrate how a computer algorithm works. Coders (people who write code) often use pseudocode as an intermediate step in programming to move from the initial planning stage to the stage of writing real, executable code. Some other coders use pseudocode for the following purposes:
Describe how the algorithm will work. Pseudocode can illustrate that a construct, mechanism, or technique can or must appear somewhere in the program.
Explain computing processes to users with lower levels of expertise. Computers need extremely strict input syntax to run programs, but people (especially non-programmers) may find it easier to learn a flexible language, Coherent, showing the purpose of each line of code.
Design code for the whole team. Advanced software engineers often insert pseudocode into their designs to help solve complex problems they find many of their programmers are facing. If you're developing programs with other coders, you may find that pseudocode helps make your intentions clearer.
Remember that pseudocode is subjective and informal. There is no set syntax that you must use when writing pseudocode, but it is often more professional to use standard pseudocode constructs that other programmers can easily understand. . If you are coding your project yourself, the most important thing is that the pseudocode helps you organize your ideas and execute your plan.
If you're collaborating with others on the same project — whether they're colleagues, junior programmers, or non-technical collaborators — it's important to use at least some of the Standard structure so people can easily understand your intentions.
If you're taking a programming course at a university, a code camp, or at work, you may have to take a test on the pseudocode "standards" that were taught. This standard will often vary depending on the educational institution and teacher.
Transparency is the primary goal of pseudocode, which can be helpful if you work within accepted programming conventions. When developing pseudocode into real code, you need to convert the pseudocode into a programming language – so it can help you shape the sketch in your mind.
Focus on the main purpose of the pseudocode. You can easily return to coding once you understand your purpose. Remembering the purpose of your pseudocode — explaining what each line of your program does — helps you stay on track as you create your pseudocode text.
Write good pseudocode
Use a plain text editor. While there are something more sophisticated, such as a Microsoft Word word processor or similar program that produces rich-text documents, pseudocode should be formatted to a minimum. to keep it simple at all times.
Plain text editors include Notepad (on Windows) and TextEdit (on Mac).
Start by noting down the command line's purpose. Dedicating a line or two to the purpose of the code helps frame the rest of the text, and saves you from having to explain the program's features to each person you want to introduce the pseudocode to.
Write only one statement per line. Each statement in your pseudocode should perform only one action for the computer. Normally, if the task list is created correctly, each task will correspond to a line of pseudocode. You should consider writing down your task list and converting that list into pseudocode, then slowly developing that pseudocode into real code that a computer can understand.
Use whitespace and indentation effectively. Inserting space between "blocks" of text keeps different parts of the pseudocode separate, and indenting each block signals that the pseudocode section is detailed information of the less indented pseudocode. .
For example, the part of the pseudocode that talks about entering numbers should be in the same "block", and the next part (like the part that talks about results) should be in a different block.
Capitalize main keywords if necessary. Depending on your pseudocode requirements or the environment in which you are publishing your pseudocode, you may need to capitalize statements that are retained in the real code.
For example, if you use the keywords "if" and "then" in pseudocode, you might want to capitalize "IF" and "THEN", such as "IF input number THEN output result" (IF enter number THEN output).
Write in simple terms. Remember that you are writing to explain what the project will do , not simply summarize the code. This is especially important when you are writing pseudocode to demo to a client who knows nothing about code, or presenting a project to a novice programmer.
You may even want to eliminate all code statements and just define each line of code in simple language. For example: Instead of writing "if input is odd, output 'Y'" (if input is odd, output is 'Y'), write "if user enters an odd number, display 'Y'" (if user Enter odd number, display 'Y').
Keep the correct sequence of pseudocode. Although the language used to edit your pseudocode should be simple, you still need to keep the order of the pseudocode correct for execution purposes.
Don't let others guess what you mean. Everything that is happening in the command needs to be described completely. It must be said that pseudocode statements are quite similar to assertions in regular English. Pseudocode usually does not use variables but describes what the program will do with objects close to the real world such as account numbers, names, or transaction numbers.
Use standard programming structures. Although there is no specific standard for pseudocode, if you use the structure of existing programming languages (sequential) it will be easier for other programmers trying to understand your steps. Use terms like "if", "then", "while", "else", and "loop" as in the language your favorite programming. Consider the following structure:
if CONDITION then INSTRUCTION — Means the statement will only be executed if a certain condition is true. "Instruction" in this case is a step that the program will perform, and "condition" means that the data must satisfy a certain condition for the program to perform the action.
while CONDITION do INSTRUCTION — Means the statement will be executed repeatedly until the condition is no longer true.
do INSTRUCTION while CONDITION — Very similar to "while CONDITION do INSTRUCTION". In this case, the condition will be checked before executing the statement, and in the other case, the statement will be executed first. Thus, then the command will be executed at least once.
function NAME (ARGUMENTS): INSTRUCTION — This means that every time a certain name is used in code, it will replace a specific statement. "Arguments" is a list of variables that you can use to clarify the statement.
Organize your pseudocode sections. If you find that there are large sections of pseudocode that define other sections of pseudocode within the same block, you may want to use parentheses or some other identifier for visibility.
Brackets—including both standard square brackets (such as [code]) and angle brackets (such as {code})—can help enclose long pseudocode.
When coding, you can add comments by typing "//" to the left of the comment line (eg //Đây là bước tạm thời.
). You can use this method when writing pseudocode to write comments that cannot be included in the code.
Check your pseudocode for readability and clarity. You should be able to answer the following questions after completing your pseudocode text:
Can someone unfamiliar with this command understand your pseudocode?
Is the pseudocode written properly so that it can be easily converted into a programming language?
Does the pseudocode describe the complete statement without leaving anything out?
Will others clearly understand each object name used in the pseudocode?
If you notice that a part of your pseudocode needs to be modified or that a step isn't clearly stated that someone else might have forgotten, you need to go back and add the necessary information.
Example of generating pseudocode text
Open a plain text editor. You can use the default program Notepad (on Windows) or TextEdit (on Mac) if you don't want to install a new program.
Define your program. Although not strictly necessary, writing a line or two at the top of the text will help distinguish it from the first indent of the program:
This program will require options from the user. If that option is suitable, the response content will be displayed; If not suitable, a notification will appear.
Write an opening paragraph. Your first statement—the first thing the program will do when it runs—should be the first line:
print greeting (print greeting) "Hello stranger!" (Hello!)
Add the next line. Set the space between the last line and the next line by typing ↵ Enter, then write the next line of code. In this example, the user will see the following dialog box:
print prompt (print to dialog box) press "Enter" to continue (press "Enter" to continue)
Call to action. In this example, the user will see the query:
print call-to-action "How are you?" (How are you?)
Show users a list of answers. In this example, after pressing ↵ Enterone more time, the user will see the list of answers below:
display possible responses "1. Fine." (fine) "2. Great!" (very strong!) "3. Not good." (unwell)
Require users to take action. This is when the program asks the user to enter an answer:
print request for input "Enter the number that best describes you:" (enter the number that best describes you)
Create an "if" statement for user input. Because there are multiple answers the user can choose from, you may want to add multiple results based on the answer the user selected:
if "1" (if "1" is selected) print response (print the answer) "Dandy!" (It's good to be healthy!) if "2" (if you choose "2") print response (print the answer) "Fantastic!" (Very healthy is great!) if "3" (if you choose "3") print response (print the answer) "Lighten up, buttercup!" (Relax a little more for your health, dear friend!)
Add error line. In case the user does not select the correct answer, you can display an error message:
if input isn't recognized (if the user's answer is not recognized) print response (print the answer) "You don't follow instructions very well, do you?" (You didn't follow the instructions correctly, did you?)
Add other parts of the program. Review your text carefully for additional detail to ensure that both you and anyone else reading the text understands the meaning. After following the method above, your finished pseudocode text will look like this:
This program requires the user to enter a number. If that number matches the available answer option, the answer will be displayed; If there is no match, a message will be displayed. print the greeting "Hello!" print dialog box Press "Enter" to continue "Enter"> Print inquiry and call to action "How are you today?" display possible answer options "1. Healthy." "2. Very strong!" "3. Not feeling well." print request input "Enter the number that best suits you:" if enter "1" print response "It's good to be healthy!" if enter "2" print the response "Very healthy is great!" if enter "3" print the response "Relax a bit to get better, my friend!" if cannot detect user input print response "You didn't follow the instructions correctly, did you?"
Save your text. Press Ctrl+ S(on Windows) or ⌘ Command+ S( on Mac), type a name, then click Save to save.
You should read it
- What is pseudocode?
- How to Write Pseudocode
- How to write curves in Photoshop
- Learn about the Write Zero method
- Why write neat and organized HTML?
- How to enable / disable Disk Write Caching in Windows 10
- What is JD? What does JD mean?
- The best apps that support writing and writing notes on Android
- 7 ways to fix, fix 'Write Protection' error on USB
- Learn to write email like a real CEO
- Activate the 'Write Protection' mode of USB on Windows 10
- Instructions for writing bank checks