Home »
Code Examples »
Groovy Code Examples
Groovy Closed And Open Ranges Code Example
The code for Groovy Closed And Open Ranges
def inclRange = 0..5
assert inclRange == [0, 1, 2, 3, 4, 5]
assert inclRange.from == 0
assert inclRange.to == 5
def exclEndRange = 0..<5
assert exclEndRange == [0, 1, 2, 3, 4]
assert exclEndRange.from == 0
assert exclEndRange.to == 4
// Support for exclusive begin added in Groovy 4.
def exclBeginRange = 0<..5
assert exclBeginRange == [1, 2, 3, 4, 5]
assert exclBeginRange.from == 1
assert exclBeginRange.to == 5
// Support for exclusive begin added in Groovy 4.
def exclRange = 0<..<5
assert exclRange == [1, 2, 3, 4]
assert exclRange.from == 1
assert exclRange.to == 4