Loop counter

Loop counter

In software engineering, a loop counter is the term often used to refer to the variable that controls the iterations of a loop (a computer programming language construct). It is so named because most uses of this construct result in the variable taking on a range of integer values in some orderly sequence (e.g., starting at 0 and end at 10 in increments of 1)

Loop counters change with each iteration of a loop, providing a unique value for each individual iteration. The loop counter is used to decide when the loop should terminate and for program flow to continue to the next instruction after the loop.

A common identifier naming convention is for the loop counter to use the variable names i, j and k (and so on if needed), where i would be the most outer loop, j the next inner loop, etc. The reverse order is also used by some programmers. This style is generally agreed to have originated from the early programming of FORTRAN[citation needed], where these variable names beginning with these letters were implicitly declared as having an integer type, and so were obvious choices for loop counters that were only temporarily required. The practice also dates back further to mathematical notation where indices for sums and multiplications are often i, j, etc.

Example

An example of C code involving nested for loops, where the loop counter variables are i and j:

for(i = 0; i < 100; i++)
   for(j = i; j < 100; j++)
      some_function(i, j);

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • loop counter — ciklų skaitiklis statusas T sritis automatika atitikmenys: angl. cycle counter; cycle index counter; loop counter; repetition counter; step counter vok. Gangzähler, m; Schleifenzähler, m; Zyklenzähler, m rus. счетчик циклов, m pranc. compteur de… …   Automatikos terminų žodynas

  • Counter turn — diagram A counter turn is a kind of one foot turn in figure skating. Unlike three turns and brackets, where the entry and exit edges follow the same curve, in a counter the entry and exit are on opposite curves. When executing a counter, the… …   Wikipedia

  • Counter Drain railway station — Counter Drain Site of former station Location Place …   Wikipedia

  • Loop of Henle — Scheme of renal tubule and its vascular supply. (Loop of Henle visible center left.) Latin ansa nephroni Gray s …   Wikipedia

  • counter — 1. n. 1 a a long flat topped fitment in a shop, bank, etc., across which business is conducted with customers. b a similar structure used for serving food etc. in a cafeteria or bar. 2 a a small disc used for keeping the score etc. esp. in table… …   Useful english dictionary

  • For loop — In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement.Unlike many other kinds of loops, such as the while loop, the for loop is often… …   Wikipedia

  • Outer loop — can refer to: The counterclockwise lanes of travel on an orbital roadway for traffic that drives on the right, or the clockwise lanes of travel for traffic that drives on the left. The outer loop (counter clockwise roadway) of Interstate 495… …   Wikipedia

  • cycle counter — ciklų skaitiklis statusas T sritis automatika atitikmenys: angl. cycle counter; cycle index counter; loop counter; repetition counter; step counter vok. Gangzähler, m; Schleifenzähler, m; Zyklenzähler, m rus. счетчик циклов, m pranc. compteur de… …   Automatikos terminų žodynas

  • cycle index counter — ciklų skaitiklis statusas T sritis automatika atitikmenys: angl. cycle counter; cycle index counter; loop counter; repetition counter; step counter vok. Gangzähler, m; Schleifenzähler, m; Zyklenzähler, m rus. счетчик циклов, m pranc. compteur de… …   Automatikos terminų žodynas

  • repetition counter — ciklų skaitiklis statusas T sritis automatika atitikmenys: angl. cycle counter; cycle index counter; loop counter; repetition counter; step counter vok. Gangzähler, m; Schleifenzähler, m; Zyklenzähler, m rus. счетчик циклов, m pranc. compteur de… …   Automatikos terminų žodynas

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”