Variables

Matthew Clark
1 min readMar 17, 2021

--

Variables are one of the most important concepts in programming. They are used to hold data and are used in all classes and methods. Variables are designed to hold many different data types. The most Basic data types are:

  • Strings- used to hold text or numbers that will not be used for calculations
  • Integers- whole numbers
  • Float- numbers that use decimal points
  • Boolean- used for logic to hold true or false options

Variables are useful because they allow you to add them to something like an equation and freely change them.

You could say:

5 + 3 = 8

Or use variables:

integer num1 = 5

integer num2 = 3

Now the equation would be:

num1 + num2 = 8

Lets say you want to set the speed of a character. The characters speed could be used in multiple calculations. Without a variable you would have to go and manually change the speed in each calculation. With a variable you only have to change the value of the speed where the variable is declared. This is a much better way to assign the speed of a character. This is one example of the power of variables and why they can be considered as the building blocks of programming.

--

--