Sorry, but that text from the manual is a bit worrying.
I've done a fair bit of assembler and still like to use Asm code blocks as sometimes it is easier to do certain bit work that way.
For that value to be undefined at the conclusion of the For loop, if it is allowed to run fully, it implies the value of iteration is being placed into the ECX register (CX in 8086, unsure about RCX, I still live in 16 bits with assembler, let’s just say ECX to keep it simple) and a standard assembler LOOP is being run.
Which makes sense. What it does also explain is why upon completion the variable has the maximum value, not one over. Usually if one is using a Repeat or While and a single step iteration, the variable, if the loop runs fully, is 1 over. Which is another reason the counter variable in a For cannot be used to determine certain actions (like testing if an item is in a list).
Thus If I am reading it correctly, it means that the iteration variable is loaded with the maximum (unsure about DownTo) value, which is then copied to the ECX, then the loop is run. So when a Break, Goto or Exit is encountered, it is actually using the value obtained from the ECX, not the variable.
That means some of my code may be technically unsound, oops. Good job I do a lot of testing.
I'm still uncertain though why it says the variable is undefined, experience tells me that it always has the maximum value if allowed to fully run. I assume that the original variable is basically treated as a scratch location just for value for the ECX, but I have no data on that. Anyway, getting caught up in trivia again.
A little demo, more to prove to myself, that Exit also works.
Function test_for( Const n : Byte ) : Byte;
Var i : Byte;
Begin
Result := 100; // default
For i := 1 To 20 Do
If i = n Then Exit( i );
End;
Procedure for_demo;
Begin
WriteLn( ' test with 3 = ', test_for( 3 ) );
WriteLn( ' test with 20 = ', test_for( 20 ) );
WriteLn( ' test with 21 = ', test_for( 21 ) );
End;
These produce the expected results, confirming Exit is seen as valid.