RANGE
Range Function (range)
The range function in Vint generates a sequence of numbers and is commonly used in loops or for creating arrays of sequential values.
Syntax
range(end) range(start, end) range(start, end, step)
Parameters
end: The upper limit of the sequence (exclusive).start(optional): The starting value of the sequence. Default is0.step(optional): The increment or decrement between each number in the sequence. Default is1.
Return Value
The function returns an array of integers.
Examples
Basic Usage
// Generate numbers from 0 to 4 for i in range(5) { print(i) } // Output: 0 1 2 3 4
Specifying a Start and End
// Generate numbers from 1 to 9 for i in range(1, 10) { print(i) } // Output: 1 2 3 4 5 6 7 8 9
Using a Step Value
// Generate even numbers from 0 to 8 for i in range(0, 10, 2) { print(i) } // Output: 0 2 4 6 8
Generating a Reverse Sequence
// Generate numbers in reverse order for i in range(10, 0, -1) { print(i) } // Output: 10 9 8 7 6 5 4 3 2 1
Notes
- Exclusive End: The
endvalue is not included in the sequence; the range stops before reaching it. - Negative Steps: If a negative
stepis provided, ensurestartis greater thanendto create a valid reverse sequence. - Non-Zero Step: The
stepvalue cannot be0, as it would result in an infinite loop or an error.