Pseudocode

From Applied Science

Writing code in a pseudo-language has two objectives in the course: first to eliminate all syntax and language's technical details. Second, to focus on logic and on the order of operations. Those who have already programmed before shouldn't have difficulties with pseudo-code. However, those who have never programmed before and have no idea about how the operations are processed by the computer, should have in pseudo-code an opportunity to not worry about a programming language's technical details. Pseudo-code serve as means to become familiar with the order of operations and with the concept of input/output of data in the computer's memory.

With pseudo-code there is no worrying about memory or performance. At best we can see that a solution to a problem shouldn't incur in an excessive number of operations or the solution to be excessively complex.

In exams the teacher might allow using pseudo-code to solve the proposed problems.

Side note: don't take pseudo-language as a programming language by itself. If you are comfortable with writing algorithms with a programming language, there is no need to write in pseudo-language then.


Here is a list of basic commands
  • Integer and real. When working with pseudo-code the teacher usually omits the declaration of variables step. However, he/she still says "we need an integer" or "we need a real var". It's just an oversimplification made to teach how to work with the computer's memory. In this case real means floating point or simple float, with an hypothetical infinite precision. In this stage there is no need to worry about how much memory the program is using.
  • Read variable. It's the equivalent to scanf(). It stores a value in a variable, which in turn is stored in the computer's memory. This command is called "destructive" because it overwrites what had been stored in memory in a certain position before. The teacher usually explains a subtle difference here: when a variable is using some memory space, that space does not need to be free in the sense of not having any value stored there, but free in the sense of not being in use by another variable. To prevent two different variables or programs from disputing the same memory space is a job for the operational system.
  • Print variable or message. It's the equivalent to printf(). The difference is that, in pseudo-code, the command totally ignores what is a function and the language's syntax. This command is called "non destructive" because it just shows the value of some variable on screen, it doesn't write anything in the computer's memory.
  • Reading vs printing. It's merely a convention, reading means inputting in memory, whereas printing means outputting from memory. In natural language reading would be output, while printing would be literally printing on paper. Although pretty simple, some students might get confused in respect to input/output.
  • ← (left arrow). It's the equivalent to the equal sign, or the assignment operation. This serve as a means to help, even those who have never programmed before, understand the difference between the assignment sign and the mathematics' equal sign. In the assignment operation, reading is done right to left, because it's the right value being assigned to the left. In mathematics reading is done left to right. The right value is equal to the left one. Although pretty simple, some students might get confused in respect to the equal sign.
  • IF, ELSE, ELSE IF, THEN. Due to dominance of english as default language for programming language's keywords, the meaning for english speakers is literal. For non english speakers the teacher uses the local language's translation, which should keep the same literal meaning. The keyword "THEN" is not used in most languages because it's implicit, the fact that the programs are made in blocks and read from top to bottom makes the "THEN" statement unnecessary.
  • Basic arithmetic. It's pretty much the same arithmetic learned in childhood. The major difference relies in the % (percent sign) operator, which means rest of division.
  • Comparison operations. The greater than, less than, greater or equal than, less or equal than signs are exactly the same signs used in math. The only exceptions are the difference sign != and the equality sign ==, both of which use different signs from those used in math.
  • Compound comparisons. For teaching purposes, the pseudo-language doesn't do compound comparisons with two or more comparisons in the same expression.
  • Beginning and end. The teachers often omit that because it's pretty straight forward, just place curly brackets { ... } to mark the beginning and the end of a block of code.
  • While. It's literal. For non english speakers the keyword is translated to a local language word which keeps the same literal meaning.
  • For and until. It's literal. For non english speakers the keyword is translated to a local language word which keeps the same literal meaning.
  • Functions, arrays, matrices and pointers. There is no equivalent for those in pseudo-code. Usually, when the teacher is teaching those topics he/she is already writing code in a real programming language.