Variables in Pseudocode

Variables are a very easy topic to understand with pseudocode. I cannot stress how easy using, assigning, and comparing variables are. It is really easy to grasp this, so we will be going over how-to assigning variables, how to use them (for conditionals, recursive functions with parameters and more), how to override variables in pseudocode and finally how to some basics about them!

We follow the pseudocode standard set by the main computer science exam board in the UK, AQA, allowing a universal set of functions and operators to be used. This makes it much easier for programmers to understand each other's code without comments!

Basics:

How to Use Variables in Pseudocode

Variables are the best way to hold values in pseudocode, which can then be used throughout the program by just referencing the name of that variable! Cool, right?

Variable Declaration

In pseudocode, it is very easy to declare variables! We just need to mention the variable name then assign a value to it. For example, if we were making a calculator app, we would make a variable called number. We could then use this later to perform our calculations, which we will get into later!

For constants it is very similar, however when declaring them, we must make sure to put their name in capital letters. For example if we were storing the user's input as a constant to then perform calculations on, we would say INPUT and then assign our value to it. This is to distinguish both variables and constants from each other in pseudocode, which helps wen working in teams of multiple developers! The value of a constant never changes during the run-time of the program

Assignment

In pseudocode, when assigning values to a variable or constant, it is best practice to use the assignment arrow (←).

So, say we have just declared the variable number, we will want to assign a value to that. So, if we were taking the user input, we would use number ← USERINPUT, as seen in the example above. This assigns the user's input from an output or prompt field and then allow us to use that data. We can also just assign regular data to it, for example a string. ExampleString ← "pseudoeditor.com is awesome", would be a valid assignment.

Using Variables

It is really easy to access the data within a variable. Say we were performing some calculations on an integer that the user entered, we would use the variable name then the operation we will be performing. We would use the number variable we assigned a value to earlier and say, number * 5, if it was an integer.

It can just be a simple thing like outputting the variable back to the user, in that case we would just use the output feature and say, OUTPUT number!

Try our pseudocode editor.

Give our pseudocode editor a go today for free - with a built-in compiler, tools to convert pseudocode to code, and project saving, PseudoEditor makes writing pseudocode easier than ever!

That is it! You have successfully declared, assigned a value to, and then used variables and constants in pseudocode. It was easy wasn't it? Now, lets move you onto a more advanced guide! You can read more of our guides and then get even better at pseudocode, without even leaving our site!