Learn to Write Pseudocode: What It Is and Why You Need It

Download Article
Step-by-step guide to using pseudocode in software development
Download Article

Want to learn how to write pseudocode? Pseudocode is a step-by-step written outline of your code that you can transcribe into the programming language you’re working with. In other words, you’re writing the flow of your code in plain language rather than official coding syntax. Many programmers use pseudocode to plan out the logic of an algorithm before writing it in code. This How.com.vn shows you how to write a pseudocode document for your computer program.

Things You Should Know

  • Pseudocode is useful for planning your program and troubleshooting the logic.
  • Use a simple plain-text editor or even pen and paper to write your pseudocode.
  • Write a statement for each line of logic in your program.
Part 1
Part 1 of 3:

Pseudocode Basics

Download Article
  1. How.com.vn English: Step 1 Understand why pseudocode is useful.
    Pseudocode is used to show how a computing algorithm should work. Coders often use pseudocode as an intermediate step in programming in between the initial planning stage and the stage of writing actual executable code. Some other uses of pseudocode include the following:
    • Describing how an algorithm should work. Pseudocode can illustrate where a particular construct, mechanism, or technique could or must appear in a program.
    • Explaining a computing process to less-technical users. Computers need a very strict input syntax to run a program, but humans (especially non-programmers) may find it easier to understand a more fluid, subjective language that clearly states the purpose of each line of code.
    • Designing code in a group setting. High-level software architects will often include pseudocode in their design process to help solve a complex problem they see their programmers running into. If you are developing a program with other coders, you may find that pseudocode helps make your intentions clear.

    Pseudocode serves as a guide for thinking through programming problems, and a communication option that can help you explain your ideas to other people.

  2. How.com.vn English: Step 2 Note that pseudocode is subjective and nonstandard.
    There is no set syntax or rules that you absolutely must use for pseudocode, but it is a common professional courtesy to use standard pseudocode structures that other programmers can easily understand.[1] If you are coding a project by yourself, then the most important thing is that the pseudocode helps you structure your thoughts and enact your plan.
    • If you are working with others on a project—whether they are your peers, junior programmers, or non-technical collaborators—it is important to use at least some standard structures so that everyone else can easily understand your intent.
    • If you are enrolled in a programming course at a university, a coding camp, or a company, you will likely be tested against a taught pseudocode "standard". This standard often varies between institutions and teachers.

    Clarity is a primary goal of pseudocode, and it may help if you work within accepted programming conventions. As you develop your pseudocode into actual code, you will need to transcribe it into a programming language – so it can help to structure your outline with this in mind.

    Advertisement
  3. How.com.vn English: Step 3 Focus on the main purpose of pseudocode.
    It can be easy to revert to writing in code once you hit your stride. Remembering the purpose of your pseudocode—explaining what each line of the program should do—will keep you grounded while creating the pseudocode document.
  4. Advertisement
Part 2
Part 2 of 3:

Writing Good Pseudocode

Download Article
  1. How.com.vn English: Step 1 Use a plain-text editor.
    It can be tempting to use a word processor (e.g., Microsoft Word) or a similar program to create a rich-text document, but pseudocode needs as little formatting as possible to keep it simple.
    • You can use pen and paper to write your pseudocode! Try different formats to find what works best for your creative programming process.

    Plain-text editors include Notepad (Windows) and TextEdit (Mac).

  2. How.com.vn English: Step 2 Start by writing down the purpose of the process.
    Dedicating a line or two to explaining the purpose of your code will help set up the rest of the document, and it will also save you the task of explaining the program's function to each person to whom you show the pseudocode.
  3. How.com.vn English: Step 3 Write only one statement per line.
    Each statement in your pseudocode should express just one action for the computer. In most cases, if the task list is properly drawn, then each task will correspond to one line of pseudocode. Consider writing out your task list, then translating that list into pseudocode, then gradually developing that pseudocode into actual, computer-readable code.
  4. How.com.vn English: Step 4 Use white space and indentation effectively.
    Using white spaces between "blocks" of text will help keep different components of your pseudocode isolated, and indenting different pieces of each block will indicate that those pieces of pseudocode go under a less-indented section.
    • For example, a section of pseudocode that discusses entering a number should all be in the same "block", while the next section (e.g., the section that discusses the output) should be in a different block.
  5. How.com.vn English: Step 5 Capitalize key commands if necessary.
    Depending on your pseudocode requirements or the environment in which you're sharing the pseudocode, you may need to capitalize commands that will remain in the actual code.
    • For example, if you use "if" and "then" commands in your pseudocode, you might want to change them to read "IF" and "THEN" (e.g., "IF <condition> THEN <output result>").
  6. How.com.vn English: Step 6 Write using simple terminology.
    Remember, you're writing about what the project will do, not summarizing the code itself. This is especially important if you're writing pseudocode to serve as a demonstration for an individual who doesn't know coding, or as a project for a beginner programmer.

    You might even want to get rid of any coding commands altogether and just define each line's process in plain language. For example, "if input is odd, output 'Y'" might become "if user enters an odd number, display 'Y'".

  7. How.com.vn English: Step 7 Keep your pseudocode in the proper order.
    While the language you use to modify your pseudocode should be simple, you still need to keep each piece of your pseudocode in the order in which it needs to be executed.
    • This will make writing the actual code easier, since your code will run top-down.
  8. How.com.vn English: Step 8 Leave nothing to the imagination.
    Everything that is happening in the process must be described completely. Pseudocode statements are close to simple English statements. Pseudocode does not typically use variables, but instead describes what the program should do with variables and data like account numbers, names, or transaction amounts.[2]
  9. How.com.vn English: Step 9 Use standard programming structures.
    Even if there is no standard for pseudocode, it will be easier for other programmers to understand your steps if you use structures from existing (sequential) programming languages. Use terms like "if", "then", "while", "else", and "loop" the same way that you would in your preferred programming language. Consider the following structures:
    • if CONDITION then INSTRUCTION — This means that a given instruction will only be conducted if a given condition is true. "Instruction", in this case, means a step that the program will perform, while "condition" means that the data must meet a certain set of criteria before the program takes action.[3]
    • while CONDITION do INSTRUCTION — This means that the instruction should be repeated again and again until the condition is no longer true.[4]
    • do INSTRUCTION while CONDITION — This is very similar to "while CONDITION do INSTRUCTION". In the first case, the condition is checked before the instruction is conducted, but in the second case the instruction will be conducted first; thus, in the second case, INSTRUCTION will be conducted at least one time.
    • function NAME (ARGUMENTS): INSTRUCTION — This means that every time a certain name is used in the code, it is an abbreviation for a certain instruction. "Arguments" are lists of variables that you can use to clarify the instruction.
  10. How.com.vn English: Step 10 Organize your pseudocode sections.
    If you have large sections of pseudocode that define other pieces of pseudocode within the same block, you may want to use brackets or other identifiers to keep everything contained.
    • Brackets—both square [code] and curly {code}—can help contain long segments of pseudocode.
    • When coding, you can add comments by typing "//" on the left side of the comment (e.g., //This is a temporary step.). You can use this same method when writing pseudocode to leave notes that don't fit into the coding text.
  11. How.com.vn English: Step 11 Double-check your pseudocode for readability and clarity.
    You should be able to answer the following questions by the end of the document:
    • Would this pseudocode be understood by someone who isn't familiar with the process?
    • Is the pseudocode written in such a way that it will be easy to translate it into a computing language?
    • Does the pseudocode describe the complete process without leaving anything out?
    • Is every object name used in the pseudocode clearly understood by the target audience?
    • If you find that a section of pseudocode needs elaboration or it doesn't explicitly outline a step that someone else might forget, go back and add the necessary information.
  12. Advertisement
Part 3
Part 3 of 3:

Creating an Example Pseudocode Document

Download Article
  1. How.com.vn English: Step 1 Open a plain-text editor.
    You can use Notepad (Windows) or TextEdit (Mac) by default if you don't want to install a new program.
  2. How.com.vn English: Step 2 Define your program.
    While not strictly necessary, writing a one- or two-sentence line at the top of the document will make clear from the beginning the intent of the program:
    This program will request a greeting from the user. If the greeting matches a specific response, the response will be delivered; if not, a rejection will be delivered.
  3. How.com.vn English: Step 3 Write the opening sequence.
    Your first command—that is, the first thing your program should do upon running—should be the first line:
    print greeting"Hello stranger!"
  4. How.com.vn English: Step 4 Add the next line.
    Place a space between the last line and the next one by pressing Enter, then create the next line of code. In this example, the user should prompt the next line of dialogue:
    print promptpress "Enter" to continue<user presses "Enter">
  5. How.com.vn English: Step 5 Add the call to action.
    In this example, the user will be prompted for a greeting:
    print call-to-action"How are you?"
  6. How.com.vn English: Step 6 Show the user a list of responses.
    Again, after pressing Enter in this example, the user should see a list of possible responses:
    display possible responses "1. Fine.""2. Great!""3. Not good."
  7. How.com.vn English: Step 7 Request input from the user.
    This is where the program will ask the user to enter a response:
    print request for input "Enter the number that best describes you:"
  8. How.com.vn English: Step 8 Create "if" commands for the user's input.
    Since there are multiple responses the user can select, you'll want to add multiple results based on their selected response:
    if "1"print response"Dandy!"if "2"print response"Fantastic!"if "3"print response"Lighten up, buttercup!"
  9. How.com.vn English: Step 9 Add an error message.
    In the event that the user incorrectly chooses a response, you can have an error message ready:
    if input isn't recognizedprint response"You don't follow instructions very well, do you?"
  10. How.com.vn English: Step 10 Add any other components of the program.
    Go through your document and add or flesh out any details to ensure that both you and anyone reading the document will understand its meaning. As per this method's example, your final pseudocode document should look something like this:
    This program will request a greeting from the user. If the greeting matches a specific response, the response will be delivered; if not, a rejection will be delivered.print greeting"Hello stranger!"print promptpress "Enter" to continue<user presses "Enter">print call-to-action"How are you today?"display possible responses "1. Fine.""2. Great!""3. Not good."print request for input "Enter the number that best describes you:"if "1"print response"Dandy!"if "2"print response"Fantastic!"if "3"print response"Lighten up, buttercup!"if input isn't recognizedprint response"You don't follow instructions very well, do you?"
  11. How.com.vn English: Step 11 Save your document.
    Press Ctrl+S (Windows) or Command+S (Mac), enter a name, and click Save to do so.
  12. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Is programming always required?
    How.com.vn English: Community Answer
    Community Answer
    Pseudocode isn't real code, but details what a program should do step by step. Knowing how to write code is necessary to writing meaningful and useful pseudocode.
  • Question
    How can I tell the difference between an odd and even number using pseudocode?
    How.com.vn English: Community Answer
    Community Answer
    Divide it by two to see if you get a remainder. If not, then it's even; if yes, then it's odd.
  • Question
    How do I spot errors in pseudocode?
    How.com.vn English: Scratchless
    Scratchless
    Community Answer
    Since pseudocode isn't real code, there can't be any errors. You decide what you want to write as pseudocode and then translate it to any coding language you'd like.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Video

      Tips

      • Pseudocode is optimal for complex programs that are hundreds to thousands of lines in length.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • Pseudocode cannot be substituted for actual code when creating a program. Pseudocode can only be used to create a reference for what the code should do.
      Advertisement

      About This Article

      How.com.vn English: Kyle Smith
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Kyle Smith. Kyle Smith is a How.com.vn Technology Writer, learning and sharing information about the latest technology. He has presented his research at multiple engineering conferences and is the writer and editor of hundreds of online electronics repair guides. Kyle received a BS in Industrial Engineering from Cal Poly, San Luis Obispo. This article has been viewed 1,051,590 times.
      How helpful is this?
      Co-authors: 61
      Updated: February 23, 2023
      Views: 1,051,590
      Categories: Programming
      Article SummaryX

      1. Write the purpose of the process.
      2. Write the initial steps that set the stage for functions.
      3. Write only one statement per line.
      4. Capitalize the initial keyword of each main direction.
      5. Write what you mean, not how to program it.
      6. Use standard programming structures.
      7. Use blocks to structure steps.
      8. Add comments if necessary.

      Did this summary help you?

      Thanks to all authors for creating a page that has been read 1,051,590 times.

      Reader Success Stories

      • How.com.vn English: Jess Cruz

        Jess Cruz

        Feb 2, 2017

        "Because of this article, I am able to understand and follow what my programming concepts professor has been trying..." more
      Share your story

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement