What is the opposite of a “priming read”? [on hold]

This is a simple terminology question about a primitive loop design pattern.

Some looping constructs require a priming read before entering the loop… Whereas other looping constructs require one final write (or the like) after exiting the loop… It seems to me that such a “trailing write” is analogous to the opposite of a priming read.

So what is the proper term for such a piece of code?


Ok guys, this is getting annoying. If you’ve never even heard the term “priming read” (or the like) in the first place, then don’t suggest other random terminology that already has a well-established definition (e.g. “loop unrolling”).

My question is whether there is a canonical (even if esoteric) term for this loop design pattern. Or if not, if there is a semi-widely-used but specific term for it. Things like “loop transformation” or “pre-loop” and “post-loop” are not specific enough to accurately differentiate this particular loop design pattern from more general loop patterns, resource acquisition / clean-up code, etc.


Here is the (simplified) C++ code snippet that motivated my question:

auto structure = structures.begin();  // structures is of type vector<structure>  // "Priming read" for the loop size_t prevID = structure->ID; int aggregateDelta = structure->delta;  // The loop while (++structure != structures.end()) {     if (structure->ID == prevID) {         aggregateDelta += structure->delta;     }     else {         reducedStructures.push_back({prevID, aggregateDelta});         prevID = structure->ID;         aggregateDelta = structure->delta;     } }  // Opposite of a "priming read" for the loop reducedStructures.push_back({prevID, aggregateDelta}); 


Based on the comments, there seems to be some confusion as to what exactly a “priming read” is in the first place and how it is different from some other concepts.

“Priming Read”

Given an unstructured loop, we may convert it to a structured loop by moving the first n statements of the loop body to the end of the loop body and duplicating those statements to outside of the loop before the loop test expression. The duplicated statements that are now before the loop entrance are what are called the “priming read.”

Unstructured Loop:

enter image description here

Structured Loop with “Priming Read”:

enter image description here

Note that given an unstructured loop that has statements between the loop entrance and the loop test expression, if we want to make it into a structured loop then the “priming read” is required for correctness. This is what makes it different from a generalized loop transformation (which appears to be what some commenters call “loop unrolling”).

Structured but Incorrect Loop without “Priming Read”:

enter image description here

“Loop Unrolling”

The movement and duplication of code involved in converting an unstructured loop into a structured loop with a “priming read” does not constitute loop unrolling, which refers specifically to a compiler optimization technique that duplicates all the code in the body of the loop for the sake of improving runtime by reducing loop control overhead. “Loop unrolling” has nothing to do with structured / unstructured programming, and it is not required for loop correctness.

Fully “Rolled” Loop Body:

enter image description here

“Unrolled” Loop Body by a factor of 4:

enter image description here