This is intended as a pre-RFC.
Currently for loops have four sections: initialization phase (A), iterate phase (B), check phase ©, and the body (D). They come together to form a standard for loop and is generally formed in a grouping similarly to the following:
A
| < - C < - |
A'' | D | A'
| B - > |
| - > ... (following code)
A' : branch back to the check call
A'': branch if the check fails
My idea is add three new blocks: then, else, and between.
- The
then block is entered when the for loop exits normally (the iteration runs to completion)
- The
else block is entered if the for loop is break-en from
- The
between block is entered after each iteration but not if the last check failed (so the iteration has finished)
Putting all of these together we could get something like the follow:
with E as the then block, F as the else block, and G as the between block.
A
| < - - - - - - - - - C
| D < - |
A'' | | < - - - - - B | B'
| | | < - C |
| B'' | C' | G - > |
| - - - | - - - | - > E - - > |
| - - - - - > F | A'
... < - |
A' : This is the branch to skip over the `else` block
A'': This is to go to the `then` block if the first iteration fails
B' : This is the branch to continue the loop after the iteration and the between block
B'': This is the break branch to go to the else block
C' : This is the branch when the usually check fails to go to the else block
How does this sound? I know that it could be complicated but other languages have at least some of these things so I don’t think that it is completely unreasonable to have.