Looping Code Segment
(Redirected from looping code segment)
Jump to navigation
Jump to search
A Looping Code Segment is a software code segment (iteration statement) that allows a code block to be repeated a certain number of times.
- Context:
- It can (typically) be initiated with a Looping Statement.
- It can range from being a Count-Controlled for Loop, a Numeric Range Loop, a Vectorized for Loops, to being an Iterator-based for Loop.
- Example(s):
- a for loop code segment, such as a foreach loop code segment.
- a while code segment.
- a do while code segment.
- a Python Loop, Scala Loop, R Loop, Perl Loop, Java Loop, C Loop, ...
- …
- Counter-Example(s):
- See: Source Code Item, Software Control Flow.
References
2015
- http://www.python-course.eu/python3_for_loop.php
- QUOTE: Like the while loop the for loop is a programming language statement, i.e. an iteration statement, which allows a code block to be repeated a certain number of times.
There are hardly programming languages without for loops, but the for loop exists in many different flavours, i.e. both the syntax and the semantics differs from one programming language to another.
Different kinds of for loops:
- Count-controlled for loop (Three-expression for loop): This is by far the most common type. This statement is the one used by C. The header of this kind of for loop consists of a three-parameter loop control expression. Generally it has the form:
for (A; Z; I)
A is the initialisation part, Z determines a termination expression and I is the counting expression, where the loop variable is incremented or dcremented. An example of this kind of loop is the for-loop of the programming language C:for (i=0; i <= n; i++)
- Numeric Ranges: This kind of for loop is a simplification of the previous kind. It's a counting or enumerating loop. Starting with a start value and counting up to an end value, like for i = 1 to 100
- Vectorized for loops: They behave as if all iterations are executed in parallel. This means for example that all expressions on the right side of assignment statements get evaluated before the assignments.
- Iterator-based for loop: Finally, we come to the one used by Python. This kind of a for loop iterates over an enumeration of a set of items. It is usually characterized by the use of an implicit or explicit iterator. In each iteration step a loop variable is set to a value in a sequence or other data collection.
- Count-controlled for loop (Three-expression for loop): This is by far the most common type. This statement is the one used by C. The header of this kind of for loop consists of a three-parameter loop control expression. Generally it has the form:
- QUOTE: Like the while loop the for loop is a programming language statement, i.e. an iteration statement, which allows a code block to be repeated a certain number of times.