Name
If Keyword
Syntax
ifConditionthenStatementifConditionthenStatementelseStatement
Description
Delphi’s if statement is the same as the
if statement in standard Pascal. The condition
must be a Boolean expression. The else part is
optional. If you have nested if statements, an
else part binds with the nearest
if statement. For example:
if X > Y then
if A > B then
WriteLn('A > B')
else
WriteLn('X > Y and A <= B');Tips and Tricks
C programmers are accustomed to using the semicolon as a statement terminator, but in Pascal a semicolon is a statement separator. In particular, no semicolon is allowed after the first statement and before the
elsekeyword. Delphi Pascal loosens some of the restrictions on semicolons, so it is easy for C, C++, and Java programmers to be lulled into the misbelief that semicolons in Delphi can terminate statements.By default, Boolean operators in Delphi implement shortcut logic (just like their brethren in C, C++, and Java). See the
andandoroperators for details.
See Also
| And Keyword, Begin Keyword, Boolean Type, Else Keyword, Or Keyword |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access