# increment 函数

将变量原地加 1，并返回它的旧值。

## 怎么写

### increment(name)

**name**

要更新的变量。接受一个变量。

## 示例

- $\displaystyle a := 1;\; \operatorname{increment}(a);\; a \; 2$

  `a := 1; increment(a); a`

  在求解器中，`a := 1; increment(a); a` 的结果是 `2`。

  [在求解器中打开](https://zh.hilberon.com/?q=a%20%3A%3D%201%3B%20increment%28a%29%3B%20a)

## 相关函数

- [pre_increment](https://zh.hilberon.com/library/pre_increment)

  把变量原地加 1 并返回新值。
- [indicator](https://zh.hilberon.com/library/indicator)

  把条件表示为数：为真时为 1，为假时为 0。
- [ifelse](https://zh.hilberon.com/library/ifelse)

  由测试条件选出的值。
- [piecewise](https://zh.hilberon.com/library/piecewise)

  按条件写出的分段取值，写作 value if condition，并可带一个 otherwise 分支。
- [function](https://zh.hilberon.com/library/function)

  没有名字的函数；也可写作 x => body。
- [pre_decrement](https://zh.hilberon.com/library/pre_decrement)

  将变量就地减 1，并返回新值。

---
Source: https://zh.hilberon.com/library/increment
