> For the complete documentation index, see [llms.txt](https://velocity-raptors-9450.gitbook.io/intro-to-frc-programming-romi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://velocity-raptors-9450.gitbook.io/intro-to-frc-programming-romi/intro-to-java/fundamentals-of-java/operations.md).

# Operations

What if you wanted to do some math in your code? Or check if a certain condition is true? You can use operators!

There are multiple types of operations that you'd use throughout coding. Most of them modify or compare some sort of data.

## Math Operations

These are used to do math expressions with data. Think of them as the different signs you'd see in a math class.

| Operator       | Purpose                                          | Syntax |
| -------------- | ------------------------------------------------ | ------ |
| Addition       | Adds two numbers.                                | a + b  |
| Subtraction    | Subtracts two numbers.                           | a - b  |
| Multiplication | Multiplies two numbers.                          | a \* b |
| Division       | Divides two numbers.                             | a / b  |
| Modulus        | Divides two numbers, but gets the **remainder**. | a % b  |

Notice how these operators only affect numbers? There are a couple of exceptions. Firstly, you can use these on chars (this isn't necessary, you won't have to worry about it), and you can use the Addition modifier to add data to a String, which is called **concatenation**. This data could be any primitive or other Strings.

Example:

```
int numbers = 12345;
int char = 'A'
int string = "Hello!"
string += char;
string += numbers;
System.out.println(string);
```

### Unary Operations

These are used to modify variables. These are quality-of-life operators that make expressions MUCH shorter than they have to be.

| Unary Operator | Purpose                        | Example   |
| -------------- | ------------------------------ | --------- |
| +=             | Adds n to the variable.        | num += 3  |
| -=             | Subtracts n from the variable. | num -= 16 |
| \*=            | Multiplies the variable by n.  | num \*= 3 |
| /=             | Divides the variable by n.     | num /= 10 |

## Logic Operators

Logic operators compare values or other expressions, which let you do logic, as the name suggests. All of these give you a Boolean from them.

| Logic Operator  | Syntax                   | Purpose                                                                                             | Example                                                                                        |
| --------------- | ------------------------ | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| == (Equals)     | value == value           | Checks if the two values are equal. (NOTE: DOES NOT WORK ON COMPOSITES- ALWAYS GIVES TRUE FOR THEM} | <p>true == true // gives you true<br>1 == 1 // gives you true<br>6 == 9 // gives you false</p> |
| != (Not equals) | value != value           | Returns if the two values are **NOT** equal.                                                        | <p>true != false // gives you true<br>2 != 2 // gives you false</p>                            |
| && (And)        | condition && condition   | Checks if both of the conditions are true.                                                          | <p>true && true // gives you true</p><p>2 == 4 // gives you false<br></p>                      |
| \|\| (Or)       | condition \|\| condition | Gives you if one of the conditions is true.                                                         | 1 == 2 \|\| 3 > 2 // gives you true because 3 > 2                                              |
| ! (Not)         | !condition               | Gives you if the condition is false.                                                                | <p>!(2 == 4) // gives you true<br>!(3 == 3) // gives you false</p>                             |

Note: you can assign these conditions to a variable. For example:

```

local 
```
