Map
Index
Random
Help
Topics
th

Topic: for loop

topics > computer science > programming > program control > Group: repetitive control



Topic:
control file
Topic:
hard real time systems
Topic:
index sequence for array access
Topic:
multiple for loop

Summary

For-loops are a commonly used control structure for repetition. They consist of a control variable, usually integer, and a range specifier, usually a sub-range of the integers. The value increment is usually 1 but other increments or decrements can be specified. The expressions defining the sub-range may be evaluated during initialization or before each iteration. Specified values may be selected or eliminated by a "where" or "unless" clause. Since sub-ranges are ordered, succ/pred functions can be used for non-integer values. An interesting twist is the converge iterator consisting of a computed step function and an epsilon terminator.

Programmers should limit for-loops to a maximum repetition count. This catches infinite loop errors and avoids the need for a proof of termination. Termination can be proved with an expression that guarantees progress for each iteration. (cbb 5/80 4/98)

Subtopic: for statement up

Quote: C's for statement is equivalent to a while statement in the appropriate format [»ritcDM7_1978c]
Quote: C's for statement keeps all loop control components together at the top of the loop; e.g., a do loop [»ritcDM7_1978c]
Quote: in C's for statement, the controlling variable retains its value after loop termination [»ritcDM7_1978c]

Subtopic: variations up

Quote: have UNLESS clause for do loops that skips specified iterations [»gramFT7_1978]
QuoteRef: morrJH8_1972 ;;758 where clause in for loops to bypass execution by boolean expression
QuoteRef: vanwA_1969 ;;173 in for loops the counter variable needed not be specified
QuoteRef: wulfWA12_1971 ;;784 in do loops all expressions only evaluated at entrance (control expressions

Subtopic: avoiding errors up

Quote: requiring a loop bound caught many design errors and was practical [»andeT_1985]
Quote: eliminate proofs of termination by avoiding loop forever constructs [»andeT_1985]

Subtopic: statistics up

QuoteRef: knutDE1_1971 ;;8 95% do loops used increment of 1

Subtopic: early examples up

Quote: replaced ALGOL 60's for statement with while statements and for loops over an arithmetic progression; was too complex [»wirtN6_1966]
QuoteRef: simscrip_1971 ;;123 specified positive or negative indexing in a for loop
QuoteRef: abraH12_1977 ;;56 generalized for on ordered types: for x:=a to b do Q (or downto) this is same as begin atype x,bb; x:=a; bb:=b; while atype.rel (x.bb) do begin Q: x:=atype.succ (x): end: Q end:
QuoteRef: sammJE_1969 ;;270 implied increment for for loops eg (i=0,1,...,5)
QuoteRef: sammJE_1969 ;;131 Laning and Ziesler '54: loops by v=1(.2)2(1)5 is 1,1.2,1.4,1.6,1.8,2, 3,4,5
QuoteRef: wirtN1_1971 ;;54 FOR I:= e1 TO (DOWNTO) e2 (fixed at start) DO (uses succ(.) or pred
QuoteRef: earlJ4_1974 ;;36 converge iterator a <= initial value, step function, epsilon stops when the step is less than epsilon
QuoteRef: morrJH8_1972 ;;759 for loop notation For range-list : exp (regular for loop) or exp: range-list (generated result) eg (x:x e b) is the set of all x in b

Related Topics up

Topic: control file (10 items)
Topic: hard real time systems (64 items)
Topic: index sequence for array access (16 items)
Topic: multiple for loop
(2 items)

Updated barberCB 6/04
Copyright © 2002-2008 by C. Bradford Barber. All rights reserved.
Thesa is a trademark of C. Bradford Barber.