Delphi – E2031 Label expected

If the identifier used in a goto statement or as a label in inline assembly is not specified as a label in your Delphi program, this error notice appears.

program Produce;

begin
  if 2*2 <> 4 then
    goto Exit; (*<-- Error message here: Exit is also a standard procedure*)
  (*...*)
Exit:              (*Additional error messages here*)
end.

How to fix it?

program Solve;
label
  Exit;            (*Labels must be declared in Delphi*)
begin
  if 2*2 <> 4 then
    goto Exit;
  (*...*)
Exit:
end.
%d bloggers like this: