HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, the term range may refer to one of three things: # The possible values that may be stored in a
variable Variable may refer to: * Variable (computer science), a symbolic name associated with a value and whose associated value may be changed * Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many ...
. # The upper and lower bounds of an
array An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
. # An alternative to
iterator In computer programming, an iterator is an object that enables a programmer to traverse a container, particularly lists. Various types of iterators are often provided via a container's interface. Though the interface and semantics of a given iterat ...
.


Range of a variable

The range of a variable is given as the set of possible values that that variable can hold. In the case of an integer, the variable definition is restricted to whole numbers only, and the range will cover every number within its range (including the maximum and minimum). For example, the range of a signed
16-bit 16-bit microcomputers are microcomputers that use 16-bit microprocessors. A 16-bit register can store 216 different values. The range of integer values that can be stored in 16 bits depends on the integer representation used. With the two mos ...
integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
variable is all the integers from −32,768 to +32,767.


Range of an array

When an array is numerically indexed, its range is the upper and lower bound of the array. Depending on the environment, a warning, a
fatal exception In computing, a fatal exception error or fatal error is an error that causes a program to abort and may therefore return the user to the operating system. When this happens, data that the program was processing may be lost. A fatal error is usual ...
, or unpredictable behavior will occur if the program attempts to access an array element that is outside the range. In some
programming languages A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
, such as C, arrays have a fixed lower bound (zero) and will contain data at each position up to the upper bound (so an array with 5 elements will have a range of 0 to 4). In others, such as
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
, an array may have holes where no element is defined, and therefore an array with a range of 0 to 4 will have ''up to'' 5 elements (and a minimum of 2).


Range as an alternative to iterator

Another meaning of ''range'' in computer science is an alternative to
iterator In computer programming, an iterator is an object that enables a programmer to traverse a container, particularly lists. Various types of iterators are often provided via a container's interface. Though the interface and semantics of a given iterat ...
. When used in this sense, range is defined as "a pair of begin/end iterators packed together". It is argued that "Ranges are a superior abstraction" (compared to iterators) for several reasons, including better safety. In particular, such ranges are supported in
Boost C++ Libraries Boost, boosted or boosting may refer to: Science, technology and mathematics * Boost, positive manifold pressure in turbocharged engines * Boost (C++ libraries), a set of free peer-reviewed portable C++ libraries * Boost (material), a material b ...
and the D standard library.D Phobos Runtime Library std.range module
/ref>


See also

* Interval


References

Programming constructs Arrays {{Compu-prog-stub