Who actually considers a loop a branch? A loop is a chunk of code that will be run N times depending on some evaluation that’s run before or after an iteration. A branch is a single decision which of several pieces of code to run, once.
Just a simple example, but the conditional branch occurs on line 14 of the generated assembly. It does a comparison (line 13) and then a conditional jump (jl, line 14).
Who actually considers a loop a branch? A loop is a chunk of code that will be run N times depending on some evaluation that’s run before or after an iteration. A branch is a single decision which of several pieces of code to run, once.
> Who actually considers a loop a branch?
interesting question...
> A loop is a chunk of code that will be run N times depending
oh! turns out you do!
> Who actually considers a loop a branch?
A loop contains a branch - keep looping or break. At least according to structured programming -- https://en.wikipedia.org/wiki/Structured_program_theorem.
https://godbolt.org/z/rz8MxhdGd
Just a simple example, but the conditional branch occurs on line 14 of the generated assembly. It does a comparison (line 13) and then a conditional jump (jl, line 14).
>Who actually considers a loop a branch?
The machine?
The "go around" branch is obviously not completely avoidable (though unrolling helps). Branches inside the loop body sometimes are.