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!

Code Icon

Basics:

  • Variables store values and data of each different data type. This means we can then later access this data by referencing the variable name.
  • Variables can store all 5 different types of data in pseudocode. Boolean, Integer, Character, String, Float/Decimal/Real. This allows us to do a lot of things in our algorithms.
  • We can reference the variables anywhere AFTER we have declared them, allowing us to pick out the value inside of them, to then use for conditional statements, loops, or even mathematical operations.
  • The value of a constant never changes during program runtime, meaning that while the programming is running, the value cannot be reassigned. So when you first assign a value to a constant, make sure it is correct.

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!


Loading...

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


Loading...

Assignment

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


Loading...

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.


Loading...


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!


Loading...

Code Icon

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!


Read Our Guide on
Subroutines
in Pseudocode



© 2023 PseudoEditor.com | All rights reserved

Useful Links

Sign InSign UpFeaturesFAQ