Difference between revisions of "If and Then"
From Free Pascal wiki
Jump to navigationJump to searchm (unlink Then) |
m (link Case) |
||
Line 38: | Line 38: | ||
* [[IF]], Tao Yue, Object Pascal Introduction | * [[IF]], Tao Yue, Object Pascal Introduction | ||
* [[;#If statement and semicolon|If statement and semicolon]] | * [[;#If statement and semicolon|If statement and semicolon]] | ||
+ | * [[Case|<syntaxhighlight lang="pascal" enclose="none">case</syntaxhighlight>]] | ||
{{Keywords}} | {{Keywords}} | ||
[[Category:Pascal]] | [[Category:Pascal]] | ||
[[Category:Control Structures]] | [[Category:Control Structures]] |
Revision as of 15:43, 12 October 2018
│
English (en) │
The if
keyword precedes a condition, must be followed by then
and a statement.
The statement may optionally be followed by else
and another statement.
If then
if condition
then true_statement
else false_statement;
condition
is a boolean
expression that evaluates to true
xor false
.
true_statement
is executed if condition
evaluates to true
.
false_statement
is executed if condition
evaluates to false
.
A compile-time error occurs if the type of condition
does not evaluate to a boolean
value.
Multiple statements in if then
branch
If you need two or more statements for true_statement
or false_statement
, enclose them within a begin
… end
Block (compound statement).
if boolean_condition then
begin
statement_zero;
statement_one;
statement_two;
end;
See also
- Official documentation: Reference guide: § “The
If..then..else
statement” - IF, Tao Yue, Object Pascal Introduction
- If statement and semicolon
case
Keywords: begin — do — else — end — for — if — repeat — then — until — while