Labeled Statements
Statements can be prefixed with a named label, so that they can be referenced and jumped to from other parts of the same method body. This is particular helpful for terminating nested loops via the break
or continue
statements.
The label can be any unique identifier, and must be separated from the statement with a colon:
method LoopTheSquare;
begin
XLoop: for x := 0 to Width-1 do begin
YLoop: for x := 0 to Width-1 do begin
if value[x,y] > 200 then break XLoop; // breaks out of the outer loop
if value[x,y] > 100 then break; // breaks the inner YLoop
end;
end;
end;
While not officially supported or encouraged, labeled statements can also be jumped to via the goto
keyword.