On Thu, 17 May 2018 18:34:04 +0200 Florian Klämpfl <flor...@freepascal.org> wrote:
>[...] Apparently this mail thread confuses some users: report https://bugs.freepascal.org/view.php?id=33753: > ISO7185: "After a for-statement is executed, other than being left by a > goto-statement, the > control-variable shall be undefined" > > http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Declarations_and_Statements_(Delphi)#For_Statements: > "After the for statement terminates (provided this was not forced by a Break > or an Exit procedure), > the value of counter is undefined." > > So this shall not be unrolled, but is still error prone, if Result is not set > after the regular end of the for loop. To avoid misunderstandings: The above clearly says, that using break/goto/exit is safe: for Result:=low to high do if Something(Result) then exit; for Result:=low to high do if Something(Result) then break; Something(Result); OTOH this is not safe: > > function tfun: integer; > > begin > > for Result:=1 to 10 do > > s:=s+1; > > end; Mattias _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel