Qore Programming Language Reference Manual  0.8.13.5
 All Classes Namespaces Functions Variables Groups Pages
RangeIterator helper functions

Functions

RangeIterator Qore::xrange (int start, int stop, int step=1, auto val)
 Returns a RangeIterator containing an arithmetic progression of integers. More...
 
RangeIterator Qore::xrange (int stop)
 Returns a RangeIterator containing an arithmetic progression of integers with start = 0 and step = 1. More...
 

Detailed Description

RangeIterator helper functions allow to use RangeItartor in easier usage in loop statements.

Example
1 foreach int i in(xrange(5))
2  printf("i=%d\n", i);
3 # resulting in:
4 # i=0
5 # i=1
6 # i=2
7 # i=3
8 # i=4
9 # i=5

Function Documentation

RangeIterator Qore::xrange ( int  start,
int  stop,
int  step = 1,
auto  val 
)

Returns a RangeIterator containing an arithmetic progression of integers.

Code Flags:
RET_VALUE_ONLY
Example:
1 xrange(2, 5); # 2, 3, 4, 5
2 xrange(2, -2); # 2, 1, 0, -1, -2
3 xrange(1, 10, 5); # 1, 6
4 xrange(0, 10, 5); # 0, 5, 10
5 xrange(-10, 10, 5); # -10, -5, 0, 5, 10
6 xrange(10, -10, 5); # 10, 5, 0, -5, -10
Parameters
startthe initial value
stopthe final value
stepthe step; the default is 1; must be greater than 0; the function throws a RANGE-ERROR exception when this argument is < 1
valan optional value to be returned instead of the default integer value
Return values
Returnsa RangeIterator containing an arithmetic progression of integers.
Exceptions
RANGEITERATOR-ERRORthis exception is thrown if step < 1
See Also
range
Note
the main difference between range() and xrange() is that range returns a real list and xrange() returns a RangeIterator
Since
Qore 0.8.6
Qore 0.8.11.1 this function takes the optional val argument
RangeIterator Qore::xrange ( int  stop)

Returns a RangeIterator containing an arithmetic progression of integers with start = 0 and step = 1.

This is an overloaded version of xrange(int, int, int) meaning xrange(0, stop, 1)

Code Flags:
CONSTANT
Example:
1 xrange(1); # 0, 1
2 xrange(-3); # 0, -1, -2, -3
Parameters
stopthe final value
Return values
Returnsa RangeIterator containing an arithmetic progression of integers with start = 0 and step = 1.
See Also
range
Note
the main difference between range() and xrange() is that range() returns a real list and xrange() returns a RangeIterator
Since
Qore 0.8.6