Variables are a key concept in programming. They allow us to create new objects that can be assigned values such as numbers, text, images, lists, etc.


We can find the variables in the Variables tab. Notice that there are five options, but we will only focus on the first three.

VarFind.png+

1. initialize global name to allows us to name our variable by changing the text "name." On the right we can add an argument that will assign the content to the variable.

A) We can add a textArgument, numberArgument, colorArgument, List, etc. to this variable.

2. Variables are useful because we can get and set them to other values.

See the examples below.


A) When you make a list you need to select an index value. If we assign the index to a value of 1, like the image below shows, then we will select the first item in the list each time we call for the list. But what if we want to assign a different value each time? Well we can use a variable.
VarUse1.png

B) First we need to create a variable and name it. So, in the image below, I create the variable "item" and assigned it a value of 1.
Var1.png
C) Now I can set my Index to my variable Item as the image shows. However, as it is now, it is still the same as before where the index is equal to 1. The difference is that I can add a statement to change the variable. I could not do this when all I had was a number argument.

VarUse2.png

D) In the code below, I tell the App that if the Variable "Item" is = to 5, then it should reset my Variable 1, If it is not equal to 5, then it should get the Variable Item (which is currently 1) and add 1 to it. So, now my current Variable "item" is equal to a value of 2. This will continue until it reaches 5, at which point it will reset to 1. Pretty cool! right?
VarUse.png

Take Away: Variables are useful because we can assign content (text, numbers, images, lists, etc.) to them and then we can adjust the content in real time.