Increment and Decrement Operators

Increment and decrement operators — (++, --)

Syntax

++symbol
symbol++
--symbol
symbol__
		

Arguments

symbol

A symbol whose value is a number.

Returns

The value of the symbol plus or minus one.

Description

These operators perform auto-increments or decrements on numeric symbols. When the ++ is placed before a symbol, it performs a pre-increment, where the value is incremented and the result is the symbol's value + 1. When ++ is placed after a symbol, it performs a post-increment. Here the result of the operation is the value of the symbol prior to being incremented. The -- operator works in the same way. These operators only take symbols as arguments. It is not possible to auto-increment or decrement an array element, list element, or instance variable.

Examples

Gamma> a = 5;
5
Gamma> ++ a;
6
Gamma> a;
6
Gamma> a ++;
6
Gamma> a;
7
Gamma> a = 5;
5
Gamma> -- a;
4
Gamma> a;
4
Gamma> a --;
4
Gamma> a;
3
Gamma>