Forgot username/password? Don't have an account?
Login with Facebook
Home » Courses » Coding Basics 2 » Using Variables
Subscribe for updates.
* New to us? log in with Facebook and get a free day pass

Using Variables

So, we have variables and we know how to create them but how can we actually use them and for what? We agree, it's time to see them in action.

The earlier videos explained what a variable is, but the discussions were brief and limited to initial declarations. Now, we will see how to use variables in the context of Flash. Basically, a variable doesn't belong to any specific data type. We can assign any type of data to a variable but we must ensure that the variable is declared initially using the same data type.

The most important feature of variables which makes them so popular is their re-usability. Variables are just like containers in which anything can be saved. For example, imagine that we need to perform multiplication on 3 sets of numbers containing 3 integers each: [(1,2,3)(2,3,4)(7,8,9)]. Now to multiply these we need to write the trace line for each set.

Instead, if we use the variables (a,b,c ) and assign the first set of values to these variables then we can perform the multiplication of the first set using a*b*c. Now, for the multiplication of the second set, nothing much changes but we assign the values of the second set to a,b and c. This way we can reuse the variables any number of times and reduce the length of the code.

Instead, if the values that are being operated are continuous numbers, then we can use the property of incrementing and looping with the help of variables which reduces the bulk of the code to a single loop. When there are many values to be calculated, using variables is the best option.

The use of variables is not just limited to numbers; strings can be assigned to them as well. We assign a string to a variable at the beginning and can perform any needed modifications on it. Later, if we want another string to be used instead of the present string, there is no need to rewrite the whole program. We just change the string that is assigned to the variable. Moreover, addition of strings seems difficult when we output the sum directly. Using variables for the addition of strings is the best option.

Got A Question?

'I love being Prime'

Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now