DelphiBasics
Else
Keyword
Starts false section of if, case and try statements
1 keyword Else(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
CaseA mechanism for acting upon different values of an Ordinal
EndKeyword that terminates statement blocks
IfStarts a conditional expression to determine what to do next
ThenPart of an if statement - starts the true clause
TryStarts code that has error trapping
 Download this web site as a Windows program.




 
Example code : Illustrate various uses of the else clause
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;
Show full unit code
  False
  Inner else satisfied
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page