"Range" (Incremental Object)
IncrementalObject["Range"][imax]
creates an object that incrementally returns the values 1, 2, …, imax.
IncrementalObject["Range"] [imin,imax]
creates an object that incrementally returns the values imin, …, imax.
IncrementalObject["Range"] [imin,imax,di]
creates an object that incrementally returns the values that use step di.
Examples
open all close allBasic Examples (3)
Create a new "Range" incremental object:
obj = IncrementalObject["Range"][2]NextValue[obj]NextValue[obj]There are no more values, and a failure object is returned:
NextValue[obj]If imin is given this is the first value:
obj = IncrementalObject["Range"][10, 15];
NextValue[obj]If di is given this used an increment for the values:
obj = IncrementalObject["Range"][1, 15, 2];
NextValue[obj];
NextValue[obj]Scope (5)
An incremental object can be used in Table:
obj = IncrementalObject["Range"][5];
Table[e, {e, obj}]An incremental object can be used in Do:
obj = IncrementalObject["Range"][2];
Do[Echo[e], {e, obj}]The sequence of incremental values may be long and need to be terminated:
obj = IncrementalObject["Range"][2^30];
TimeConstrained[Do[max = e, {e, obj}], 1];
maxA "Range" incremental object can be used as a source for other incremental objects:
obj = IncrementalObject["Select"][IncrementalObject["Range"][1000], PrimeQ];Return a list of prime numbers found in the first 1000 integers:
Table[e, {e, obj}]A "Range" incremental object uses less memory than the equivalent Range:
MaxMemoryUsed[obj = IncrementalObject["Range"][1000];Do[e, {e, obj}]]MaxMemoryUsed[obj = Range[1000];Do[e, {e, obj}]]Properties & Relations (2)
InputForm (1)
InputForm returns the serialized contents of a "Range" incremental object:
InputForm[IncrementalObject["Range"][2, 5, 2]]This serialized form can be used to recreate the incremental object:
IncrementalObject["Range", {"Iterator" :> {2, 5, 2}, "Count" :> 0}]SameQ (1)
SameQ can be used to test whether two incremental objects contain the same sequence at the same position:
obj1 = IncrementalObject["Range"][10];
obj2 = IncrementalObject["Range"][10];
obj1 === obj2If one objects moves to the next value, the two objects are no longer the same:
NextValue[obj1];
obj1 === obj2Advancing the other object means that they are both now the same:
NextValue[obj2];
obj1 === obj2See Also
Related Guides
History
Introduced in 2026 (15.0)