Hey, this
tutorial will be more explanation on variables. As we saw on the last tutorial,
variable is anything that stores a piece of string or number. The computer
doesn’t care what you name your variables. You can name them anything but would
be easier if they are something you can relate to the object. Let’s see how we
can use variables.
As you can see above, I created three
variables and stored 7 on ‘Ronaldo’ , 10 on ‘Messi’ and 20 on VanPersie. And when I add Messi with VanPersie, it
calculated to 30. See that’s how you use variables with numbers. Here’s another
way to use variables.
Now that
was how variables are used to store a string of text. In the first line I
created a variable and named it languages. I stored three languages in it. And later,
when I ordered to print languages it printed
the strings of text stored in ‘languages’. Pretty
easy.
As I said
earlier the computer doesn’t care what you name your variables, but you should.
Giving variables names that reflect what type of data they contain makes it
easier to understand what a program does. Instead of ‘languages’, we could have named that variable ‘AppleSauce’ or ‘MenelikTheSecond’ or
anything weird. The computer will run the program the same way it did with ‘languages’.
Variable
names are case-sensitive. Case-sensitivity means the same variable in a different
case is considered to be an entirely separate variable name. So languages is different from Languages , lANguaGes, LaNguAges or languageS.
That was all
for this tutorial. It is a building block of any programming. We’ll learn about
selection on the next tutorial. I think this will get more fun when we start
building our own games. See ya!
No comments:
Post a Comment