Designing an app in Pseudocode. Pseudocode, a notation resembling a simplified programming language, used in  program design.

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm.

It uses the structural conventions of a normal programming language, but is intended for human reading rather than machine reading, hence programdesign.

Remember that Designing an app in Pseudo code is subjective and nonstandard.

There is no set syntax 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.

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 Designing an app in Pseudo code, and it may help if you work within accepted programming conventions.

As you develop your Designing an app in Pseudo code 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.

See also: Computer Programming Business Requirements Analysis

Understand algorithms. An algorithm is a procedure for solving a problem in terms of the actions that a program will take and the order in which it will take those actions. An algorithm is merely the sequence of steps taken to solve a problem. The steps are normally “sequence,” “selection, ” “iteration,” and a case-type statement.

  • In C, “sequence statements” are imperatives.
  • The “selection” is the “if then else” statement.
  • The iteration is satisfied by a number of statements, such as the “while,” ” do,” and the “for.”
  • The case-type statement is satisfied by the “switch” statement.

Pseudocode Examples – Designing an app in Pseudo code

Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a “text-based” detail (algorithmic) design tool.

The rules of Pseudocode are reasonably straightforward.

All statements showing “dependency” are to be indented.

These include while, do, for, if, switch.

Examples below will illustrate this notion:


Examples: Designing an app in Pseudo code

1) A simple if statement with two results.

If a student’s grade is greater than or equal to 60

    Print “passed”

else

    Print “failed”

2) A while loop until 10 grades input then display the average grade.

Set total to zero

Set grade counter to one

While grade counter is less than or equal to ten

    Input the next grade
    Add the grade into the total

Set the class average to the total divided by ten

Print the class average.


3) Same as above but has an exit word Sentinel instead of predefined number of grades.

Initialize total to zero

Initialize counter to zero

Input the first grade

while the user has not as yet entered the Sentinel

    add this grade into the running total
    add one to the grade counter
    input the next grade (possibly the Sentinel)

if the counter is not equal to zero

    set the average to the total divided by the counter
    print the average

else

    print ‘no grades were entered’

4) A simple algorithm to check 8 or more students passed, then raise tuition.

initialize passes to zero

initialize failures to zero

initialize student to one

while student counter is less than or equal to ten

    input the next exam result
    • if the student passed

      • add one to passes

else

    • add one to failures

add one to student counter

print the number of passes

print the number of failures

if eight or more students passed

    print “raise tuition”

5) Search and replace pseudocode.

Consider a simple example program. Imagine that the program must replace all instances of the word “foo” in a text file.

The program will read each line in a file, look for a certain word in each line, and then replace that word.

You can see that the steps to be repeated are indented with spaces in the pseudocode, just like it would be ideally in real code.

A first draft of the pseudocode might look like this:

  • open the file
  • for each line in the file:
    • look for the word
    • remove the characters of that word
    • insert the characters of the new word
  • then close the file.

6) Use pseudocode iteratively: write it once, and then revise it later. One of the strengths of pseudocode is that you can lay out the basics and leave the hard stuff for later.

Notice that in the word-replacement example above, there is no detail about how to look for the word.

You, the programmer, can re-write the pseudocode to include algorithms for removing the characters of the word, and inserting the characters of the new word.

A second draft of the pseudocode may look like this:

  • open the file
  • for each line in the file:
    • look for the word by doing this:
      • read the character in the line
      • if the character matches, then:
        • if all of the following characters match,
        • then there is a true match.
        • remove the characters of that word
        • insert the characters of the new word
  • then close the file.

7) Use pseudocode to add features. Pseudocode helps programmers think their way through a problem, just like intermediate steps in a math problem.

When used properly, pseudocode can make a complicated programming challenge seem simple.

You can improve the pseudocode little by little, one step at a time:

  • open the file
  • ask the user for the word to be replaced
  • ask the user for the word with which to replace it
  • for each line in the file:
    • look for the word by doing this:
      • read the character in the line
      • if the character matches, then:
        • if all of the following characters match,
        • then there is a true match.
    • Count the occurrence of that word.
    • remove the characters of that word
    • insert the characters of the new word
    • display the number of occurrences of the word,
  • then close the file.

Some Keywords That Should be Used

For looping and selection, the keywords that are to be used include:

Do While…End Do

Do Until…End do

Case…End Case

If…End if

Call … with (parameters)

Call

Return ….

Return

When

Always use scope terminators, for loops and iteration. Scope terminators are the words after the … in the keywords above. ie: End if, End do, etc…

As verbs, use the words Generate, Compute, Process, etc. Words such as set, reset, increment, compute, calculate, add, sum, multiply, … print, display, input, output, edit, test, etc. with careful indentation tend to foster desirable pseudocode.

Do not include data declarations in your pseudo code.

Remember the three basic constructs that control algorithm flow. If you can implement a “sequence” function, a “while” (looping) function, and an “if-then-else” (selection) function, then you have the basic tools that you need to write a “proper” algorithm.

  • SEQUENCE is a linear progression where one task is performed sequentially after another. For example:
    • READ the height of a rectangle
    • READ the width of a rectangle
    • COMPUTE area as height times width
  • WHILE is a loop (repetition) with a simple conditional test at its beginning. The beginning and end of the loop are indicated by two keywords WHILE and ENDWHILE. The loop is entered only if the condition is true. For example:
    • WHILE Population < Limit
      • Compute Population as Population + Births – Deaths
    • ENDWHILE
  • IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action. A binary choice is indicated by these four keywords: IF, THEN, ELSE, and ENDIF. For example:
    • IF HoursWorked > NormalMaximum THEN
      • Display overtime message
    • ELSE
      • Display regular time message
    • ENDIF

Standard Pseudocode Procedure

  1. 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.
    • Task list:
      • Read the name, hourly rate, hours worked, deduction rate
      • Perform calculations
      • gross = hourly rate * hours worked
      • deduction = gross pay * deduction rate
      • net pay = gross pay – deduction
      • Write name, gross, deduction, net pay
    • Pseudocode:
      • READ name, hourlyRate, hoursWorked, deductionRate
      • grossPay = hourlyRate * hoursWorked
      • deduction = grossPay * deductionRate
      • netPay = grossPay – deduction
      • WRITE name, grossPay, deduction, netPay
  2. Capitalize the initial keyword of each main direction. In the above example, READ and WRITE are capitalized to indicate that they are the primary functions of the program. Relevant keywords might include: READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE, REPEAT, and UNTIL.
  3. Write what you mean, not how to program it. Some programmers write pseudocode like a computer program: they write something like “if a % 2 == 1 then“. However, most readers must stop to reason through lines that are so abstractly symbolic. It is easier to understand a verbal line like “if an odd then“. The clearer you are, the more easily people will be able to understand what you mean.
  4. 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 close-to-real-world objects such as account numbers, names, or transaction amounts.
    • Some examples of valid pseudocode are:
      • If the account number and password are valid then display the basic account information.
      • Prorate the total cost proportional to the invoice amount for each shipment.
    • Some examples of invalid pseudocode are:
      • let g=54/r (Why: Do not use variables. Instead, you should describe the real-world meaning.)
      • do the main processing until it is done (Why: You should be specific about what ‘main processing’ means, and what qualifies the process as ‘done’.)
  5. 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. “Condition” means that the data must meet a certain set of criteria before the program takes action.
    • while CONDITION do INSTRUCTION – This means that the instruction should be repeated again and again until the condition is no longer true.
    • 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. So in the second case, INSTRUCTION will be conducted at least one time.
    • for a = NUMBER1 to NUMBER2 do INSTRUCTION – This means that “a“, a variable, will be automatically set to NUMBER1. “a” will be increased by one in every step until the value of the variable reaches NUMBER2. You can use any name for the variable that you think fits better than “a“.
    • 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.

Use blocks to structure steps. Blocks are syntactic tools that tie several instructions together into one instruction. You can use blocks to order information (say, steps in Block 1 always come before steps in Block 2) or simply to wrap information (say, Instruction1 and Instruction2 are thematically related). In general, indent all statements that show “dependency” on another statement. There are two ways to do this.

  • Using curled brackets:
    • {
    • INSTRUCTION1
    • INSTRUCTION2
    • …}
  • Or using spaces. When using spaces, every instruction of the same block has to start at the same position. Blocks within blocks have more spaces than the parent block. An instruction from a parent block ends the child block, even if there is an instruction later with the same amount of spaces in front.
    • BLOCK1
    • BLOCK1
      • BLOCK2
      • BLOCK2
        • BLOCK3
      • BLOCK2
        • BLOCK3
    • BLOCK1

Practicing Pseudocode – Designing an app in Pseudo code

  • Start by writing down the purpose of the process. This gives you a way to judge whether the pseudocode is complete: in short, if the pseudocode accomplishes the purpose, it is complete. Continue by writing down the process. If the process is simple, this may take only one pass. Look at what you have written down and ask the following questions:test
    • Would this pseudocode be understood by someone who is at least somewhat 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?