> For the complete documentation index, see [llms.txt](https://docs.revrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.revrobotics.com/rev-professional-development-technical-path/blocks-boot-camp/variables.md).

# Introduction to Variables

## What is a Variable?

In math, it's common to see problems like below:

$$
a + 8 = 15
$$

We can solve for "a" to determine a = 7, right? Then we could solve a variety of additional calculations with that knowledge like:

$$
a + 10 = ?
$$

$$
2a = ?
$$

$$
34/a = ?
$$

**Variables** in programming serve the same role! We use a variable to represent a value, or other information, that then can be used throughout the program.&#x20;

### Why use a Variable?

Consider for a moment: Why would we use a variable when we could simply use the number on its own?

While there are several reasons, one of the biggest is that variables can greatly help with organization in a program and streamline making changes.&#x20;

Rather than having to hunt down every place a value has been used in a program, if we need to make a change we can adjust just the variable and be done! This helps to prevent mismatches that could come from one value being updated, but another missed.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2Fyz8pH9Qs4YBof8k86k5f%2Fimage.png?alt=media&amp;token=dcca3868-6fa8-4105-a8cd-f367f4ca7b22" alt=""><figcaption><p>An example of a variable used in multiple places</p></figcaption></figure>

Variables might also be used to store the results of a calculation in a program to then be used wherever it's needed, such as the values from joystick movements on the gamepad.&#x20;

### Types of Variables

**Constant variables** do not change after being set. These are often set during initialization or at the start of an OpMode.&#x20;

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2FgVL0gcCUerZ3AXOzn3Qw%2Fimage.png?alt=media&amp;token=291deec4-b89c-49a1-a1f9-c922f34b83ca" alt="" width="501"><figcaption><p>Example of Constant Variables in Blocks</p></figcaption></figure>

These variables might include something like a target velocity, position, or power that will be reused or other settings that need to remain consistent whenever called.&#x20;

**Non-constant variables** are often just called variables. These change throughout the program, but may be set during initialization or the beginning of an OpMode to a default.&#x20;

These variables, for example, may store the results of a calculation run in the OpMode or data collected by a sensor.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2FanSSjzbVAAuwRSe8RDzN%2Fimage.png?alt=media&amp;token=83082607-2d44-4102-a164-92c85611867f" alt=""><figcaption><p>Example of Non-Constant Variables in Blocks</p></figcaption></figure>
