SmartPascal
Else
Keyword
Starts false section of if, case and try statements
1   if Condition then Statement else Statement;
2   case Expression of
    Case clauses
    ...
    else
      Statements
  end;
3   try
    Statements
    ...
  except
    Exception statements
    ...
  else
    Statements
  end
Description
The Else keyword is part of the If, Case and Try statements. It is used to start the section of code executed when earlier conditions are not satisfied.
 
See details of each of these statements for further details.
Related commands
Case A mechanism for acting upon different values of an Ordinal
End Keyword that terminates statement blocks
If Starts a conditional expression to determine what to do next
Then Part of an if statement - starts the true clause
Try Starts code that has error trapping
 
Example code : Illustrate various uses of the else clause
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

begin
  // Note the lack of a ';' after the 'then' clause
  if False
  then ShowMessage('True')
  Else ShowMessage('False');

  // Nested if statements - Delphi sensibly manages associations
  if true then
    if false then
      ShowMessage('Inner then satisfied')
    Else
      ShowMessage('Inner else satisfied')
  Else
    ShowMessage('Outer else satisfied')
end;
 
end.
Hide full unit code
   False
   Inner else satisfied