In this lesson,
we're going to discuss variables.
Now, variables are used to store values
and data for different data types.
Basically, a variable can store anything
based on that data type.
So when we talk about data types,
we are talking about five different things
that you may come across.
This includes things like Booleans, integers,
float, decimal, or real numbers, characters, or strings.
When we talk about a Boolean,
this can hold essentially two values,
either true or false.
Depending on the programming language,
this will either be designated by the word true or false,
the letter T or F, or even the numbers 1 and 0.
This does depend specifically on the
programming language you're going to use.
Now, basically in this section of the course,
we're going to be focusing our discussions
on the use of Pseudocode.
Pseudocode is essentially a made up language
that isn't representative
of any singular programming language like Bash, or Python,
or PowerShell, or Ruby, or Pearl, or JavaScript.
Instead, it's more of a generalized form
that we can use when discussing these characteristics
of a programming language.
As we move into the next section of the course,
I will break down each programming language individually
in its own lesson where we can then talk specifically
about variables in those languages.
But from a Pseudocode perspective
and something that holds true across most languages,
when you're dealing with a Boolean,
it's either going to be true or false, a 1 or a 0.
The second type of variable we have is known as an integer.
Now, an integer is simply a variable
that will store a number,
but a specific type of number.
It has to be an integer or a whole number.
This integer could be positive or negative,
something like 5, 15, 100,
negative 30, 58 or whatever.
It doesn't really matter.
This integer can be however big or small you want,
as long as it stays within the bounds
of that particular integer value
in your programing language that you're going to be using.
In terms of Pseudocode, though,
we're just talking about the fact that an integer
holds a whole number.
If the number is a decimal,
we call this either a float, a decimal, or a real number.
This is a different data type.
So if I wanted to store the amount of money
in my wallet in an integer, I can say I have $53,
but if I had $53.22, I can't store that as an integer.
Instead, I have to place that in a float, decimal
or real number variable because those have a decimal point.
Anytime you hear a decimal, remember,
in computers, we usually talk about this
as a float or a decimal or real number.
The next type of variable you can have
is what's known as a character.
Now a character is only going to store one ASCII character.
That character could be a number like the number 5,
or it could be a letter like the lowercase a
or the capital T.
It really doesn't matter
as long as it's something that is an ASCII character.
Now, when you're dealing with a character,
remember this only stores one character, though.
If I wanted to store my name like, Jason,
that's five characters,
and so I can't store that in a single variable
that is classified as a character.
And this brings us to our fifth type,
which is known as a string.
A string is essentially multiple characters.
So if I wanted to store my name, Jason,
I could do that inside a variable that has a type of string,
because a string can have lots of letters
or a series of letters and numbers
that are stored as a string.
Now, one word of warning when you're dealing with variables,
yes, you can store a number like 157 inside of the variable
that is classified as a straight but if you do that,
you can no longer do mathematical functions on that value.
If I wanted to take two numbers and add them together,
I need to add them of the same type.
I cannot add two strings together in that manner.
Instead, I can have the number 157
and the number 3 in two different variables
and add them together if they're both integers.
In that case, the result will be 160.
Now, if I have a decimal number and I have an integer,
I can add those two together
because they are two different types of variables.
So you'd have to convert that integer type
into a decimal type first,
and then add it to the one that is a decimal.
In Pseudocode to keep things easy,
we don't have to define the data type for each variable,
but in some real programming languages,
you do have to define the data type
when you initialize the variable
at the beginning of your programs.
The next thing we need to cover in terms of variables
is how to use them.
The important thing to remember with the variable
is that variables can change
throughout the execution of your program.
For example, I might have my program initiate my variables
with a starting value.
Let's say I set the variable first name to equal Jason
and the last name to equal Dion.
Then I ask, as part of my program,
for you to enter a first name.
You might put in something like Mark.
Then it's going to change my first name field
into the name you entered.
So now, instead of Jason Dion,
we now have the variables of Mark Dion,
and this is the benefit of using a variable.
It can change throughout the course of your program.
Anytime you want to use the first name variable,
you'll simply call it by using its variable name,
and that will display to the screen.
If you're using Pseudocode, you can define these variables
by having a lowercase word Azure variable.
For example, first name is all lowercase,
and that is now a variable called first name.
Conversely, if you have something that looks like a variable
but is in all uppercase letters,
this is considered a constant inside of Pseudocode.
Now, a constant is very similar to a variable,
and they're defined basically the same way.
The only difference is once you define a constant,
it cannot be changed in the program.
So why would you want to use a constant?
Well, some things aren't going to change
during the execution of your programs.
For example, if I was writing a code
to be able to calculate the area of a circle
when you gave me the radius,
I can do that by using the equation pi r squared.
Now, r is the variable that you're going to supply me,
but pi is a constant.
Pi should always equal 3.14159
265359,
or however many significant digits you want to list.
By creating the constant pi at the top of your program,
you can define exactly what you want to use for pi.
Maybe you don't need it to be that precise,
so instead you're going to use 3.14
or 3.14159 and call it good.
That is your ability inside
of defining a constant within a program.
The final thing we need to talk about
in terms of our Pseudocode
is how we're going to define those variables and constants.
Now, we already had the names being either lowercase
for variables or uppercase for constants,
but we haven't talked about
how we're going to define the value.
Well, the easiest way to do this
is to use a symbol like an equal sign.
In most programming languages,
you're simply going to use an equal sign
to define the value that you want
on the left side of the equal sign.
For example, you already saw that I used
first name equals Jason.
That is assigning the word Jason.
That set of characters that are grouped together
as a string into the variable for first name.
Similarly, with a constant of pi, we can equal 3.14,
assigning that static decimal number
into the constant we called pi.
This is how you can start to use variables
inside of your Pseudocode,
and that's the basics of variables.
Remember, variables are going to be something that
you can use to change throughout the course of your program,
and they can take one of five types, a Boolean, an integer,
a float, decimal, or real number, a character or a string.