Delphi Error – E2153 ‘;’ not allowed before ‘ELSE’

Delphi Compiler Error

E2153 ‘;’ not allowed before ‘ELSE’

Reason for the Error & Solution

You have placed a ‘;’ directly before an ELSE in an IF-ELSE statement. The reason for this is that the ‘;’ is treated as a statement separator, not a statement terminator – IF-ELSE is one statement, a ‘;’ cannot appear in the middle (unless you use compound statements).

program Produce;

  var
    b : Integer;

begin
  if b = 10 then
    b := 0;
  else
    b := 10;
end.

The Delphi language does not allow a ‘;’ to be placed directly before an ELSE statement. In the code above, an error will be flagged because of this fact.

program Solve;

  var
    b : Integer;

begin
  if b = 10 then
    b := 0
  else
    b := 10;

  if b = 10 then begin
    b := 0;
  end
  else begin
    b := 10;
  end;

end.

There are two easy solutions to this problem. The first is to remove the offending ‘;’. The second is to create compound statements for each part of the IF-ELSE. If $HINTS are turned on, you will receive a hint about the value assigned to ‘b’ is never used.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...