# Postfix and Prefix Operators

Another addition to the Lua++ language is prefix and postfix operators. These can be used to increment and decrement a specific variable within your program. These types of operators are frequently found in C-based programming languages like C++, C#, or Java. The following example demonstrates how to use a postfix increment operator to print numbers from 0 to 9.

```lua
local v: number = 1

while v < 10 do
    print(v)
    v++        -- increment value of v by 1
end
```

The `++` operator will first return the value of that variable and then increment it by 1. If you want to increment the value prior to returning it, you can prefix your variable reference with the `++` operator.

```lua
local v: number = 1
 
print(v++)  -- prints 1
print(++v)  -- prints 2
```

To decrement variables the `---` operator is used which functions exactly like the `++` operator. Lua uses `--` to indicate the beginning of a comment, which conflicts with the conventional `--` decrement operator of many other programming languages. Therefore, Lua++ provides a workaround that disables standard Lua comments using a macro which can be found here: [comment](https://docs.luaplusplus.org/language-improvements/macros/comment "mention").


---

# 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/postfix-and-prefix-operators.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.
