Difference between revisions of "If and Then"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed template loop)
m (Fixed syntax highlighting; deleted category included in page template)
Line 1: Line 1:
{{LanguageBar}}
+
{{then}}
 +
 
 +
 
 +
Back to [[Reserved words]].
 +
 
  
 
The <syntaxhighlight lang="pascal" enclose="none">if</syntaxhighlight> [[Keyword|keyword]] precedes a condition, must be followed by <syntaxhighlight lang="pascal" enclose="none">then</syntaxhighlight> and a statement.
 
The <syntaxhighlight lang="pascal" enclose="none">if</syntaxhighlight> [[Keyword|keyword]] precedes a condition, must be followed by <syntaxhighlight lang="pascal" enclose="none">then</syntaxhighlight> and a statement.
Line 5: Line 9:
  
 
== <syntaxhighlight lang="pascal" enclose="none">If then</syntaxhighlight> ==
 
== <syntaxhighlight lang="pascal" enclose="none">If then</syntaxhighlight> ==
 +
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
if condition
 
if condition
Line 29: Line 34:
  
 
== See also ==
 
== See also ==
 +
 
* Official documentation: [https://www.freepascal.org/docs-html/ref/refsu57.html Reference guide: § “The <syntaxhighlight lang="pascal" enclose="none">If..then..else</syntaxhighlight> statement”]
 
* Official documentation: [https://www.freepascal.org/docs-html/ref/refsu57.html Reference guide: § “The <syntaxhighlight lang="pascal" enclose="none">If..then..else</syntaxhighlight> statement”]
 
* [[IF]], Tao Yue, Object Pascal Introduction
 
* [[IF]], Tao Yue, Object Pascal Introduction
Line 35: Line 41:
  
 
{{Keywords}}
 
{{Keywords}}
[[Category:Pascal]]
 
[[Category:Control Structures]]
 

Revision as of 07:20, 1 March 2020

Deutsch (de) English (en) français (fr) русский (ru)


Back to Reserved words.


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


Keywords: begindoelseendforifrepeatthenuntilwhile