# Compound Assignments

When writing programs, it is generally necessary to increment a variable. The problem with Lua and many other high-level scripting languages is that they don’t provide an efficient way to do such a this:

```lua
a = a + 13
```

Although this method is simple and straightforward, it becomes inefficient when dealing with large-scale programs and longer variable names. Additionally, the VM needs to reference the value of `a`, add `13` to it, and update the original value of `a`. An operator for actions like this would decrease execution time and improve developer productivity. The following code block shows an example using the `+=` compound assignment.

```lua
a += 13
```

There is a compound assignment operator for each arithmetic and string operation in Lua, such as (`+=`, `-=`, `/=`, `*=`, `^=`, `%=`, and `..=`). Each operation assigns a variable the value of itself with the operation performed on the original value.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luaplusplus.org/language-improvements/compound-assignments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
