Programming basicsVariables

Programming is writing computer code to create a program, in order to solve a problem. To program a computer, you need to know how programs are constructed.

Part of Computer ScienceProgramming

Variables

Understanding variables

Sometimes we need computers to remember the we give it and that it calculates during programs. A can be thought of as a box that the computer can use to store a value. The value held in that box can change or ‘vary’. A can use as many variables as it needs it to.

All variables are made up of three parts:

  • a name
  • a type
  • a value

Why use variables?

Variables are extremely useful when . If a variable is used for the length of a side in a simple program to calculate the perimeter of a square, it is easy to calculate the perimeter of a different sized square, simply by changing the value of the variable.

Variables are a key element of programming. They are used for calculations, for storing values for later use, in decisions and in iteration.