Using variables is a way to greatly enhance what your code can do because it allows you to change a given value every time your code runs, or the code that would come out of this pseudocode, without you having to go back to the code to make changes.
Defining a Variable
To define a variable, we will often use a keyword like define
, define
, or set
. Some people will want to define what type of variable it is, a number
, a string
, a boolean
, etc. But this is not required, and in fact, not all languages will even require it.
You can see some examples below.
define x
set y as number
declare string name
Getting a Value for a Variable
The values for a variable can be hard coded by the software developer, entered by a user, or read from an external source such as a file, database, web service, or potentially something we’ve yet to think of yet.
For what we’re doing, we’re focusing on values entered by the user. This will of course change over time with future programming classes, but we’re keeping it simple for our first class.
We’ll typically use a simple key word to let others know what we’re trying to do. Something like input
or get
. From that, we may assign a prompt to the variable.
define name
input name = "Please enter your name: "
define age
input "What is your age?" -> age
Notice how I use a symbol like a colon or a question mark to let the end user know that I am prompting them to enter a value. The clearer I can be, the better, and less likely there will be a problem.
Using Variables in Pseudocode was originally found on Access 2 Learn
One Comment
Comments are closed.