Simple Variables
Today we will be learning about variables. But, what is a variable? A variable is a symbol or a bit of code whose value can be changed.Therefore, every time we call a program, we can change the variable without changing the code itself. So, we can choose how long are the sides of our square going to be every time we call the program itself. So, how do we do that? Well, we know that if we want to, we can change the program so the FD in the code is not 100, but 50. But with variables we do not need to do that because when we call the program, we can, instead,write the lenght of the sides withthe name of the program (E.g. Square 50). The square means that we are calling the program named "SQUARE", and the 50 is a variable which we have given the value of 50. But to make the program have a variable in it, we will have to make small adjustments to the program itself. So, let's take a look.
Here should be your first variable example...
So, what has changed? First of all, we put a :A after the name.This is an example of a variable. You can name the variable however you want, but for this example, I named it "A". You need to always put a colon in front of a variable. So, to make the variable work, you need to replace all the numbers you want the variable to cover, or all numbers you want to be exchangable, flexible. In this example, I just wanted the sides of the square to be different lenght because if the angle was flexible (if i made the RT 90 a variable, :X for example,) then that wouldn't be a square, wouldn't it? Try creating a pentagon with the side size 100, 50 and 150 without writing 3 separate programs or changing the one you wrote. You can do so much with this and try, because in the next lesson, we will be taking a look at IF and IFELSE commands!