16.11. Range Operator

The binary range operator is represented by the colon :. It is syntactically right-associative (it groups right-to-left). The range expression yields a contiguous range of integral values.

Range Expression
[54]RangeExpression::=ConditionalExpression [ ':' RangeExpression ]  

Binary numeric promotion is performed on the operands. The type of the range expression is the promoted type. It is a compile-time error if this type is not int or long.

The range expression is a generator expression. Its sequential evaluation evaluates both operands and yields all values of its type between the value of the first and the value of the second operand in ascending order, including the boundary values. If the value of the first operand is greater than the value of the second operand, no value is yielded.