Looping Code Segment
(Redirected from looping code segment)
Jump to navigation
Jump to search
A Looping Code Segment is a software code segment that implements iteration control (through loop statements and iteration blocks).
- AKA: Loop Code Block, Iteration Code Segment, Loop Implementation Block.
- Context:
- It can typically control Program Flow through loop conditions.
- It can typically process Data Collections through iteration mechanisms.
- It can typically modify Program State through repeated execution.
- It can typically manage Loop Variables through iteration control.
- ...
- It can often handle Loop Termination through exit conditions.
- It can often support Loop Optimization through performance mechanisms.
- It can often implement Loop Nesting through nested iteration.
- ...
- It can range from being a Simple Iterator to being a Complex Loop Structure, depending on its iteration complexity.
- It can range from being a Basic Count Loop to being a Vectorized Loop Implementation, depending on its execution model.
- It can range from being a Condition-Based Loop to being an Iterator-Based Loop, depending on its control mechanism.
- ...
- Example(s):
- Basic Loop Structures, such as:
- Language-Specific Loops, such as:
- a Python Loop for python iteration.
- a Java Loop for java iteration.
- a Scala Loop for scala iteration.
- a R Loop for r iteration.
- a Perl Loop for perl iteration.
- a C Loop for c iteration.
- Advanced Loop Types, such as:
- ...
- Counter-Example(s):
- a Declarative Software Statement, which specifies desired outcome rather than iteration steps.
- a Software Function, which defines single operation rather than repeated execution.
- a Recursive Code Segment, which uses recursion rather than iteration.
- See: Source Code Item, Software Control Flow, Iteration Pattern, Loop Implementation, Loop Optimization, Program Control Structure.
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.