Difference between revisions of "If and Then"

From Lazarus wiki
m
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 5: Line 5:
 
== If then ==
 
== If then ==
  
<delphi>
+
<syntaxhighlight>
 
   if condition
 
   if condition
 
     then true_statement
 
     then true_statement
 
     else false_statement;
 
     else false_statement;
</delphi>
+
</syntaxhighlight>
  
 
Condition is a [[Boolean]] expression that evaluates to [[True|true]] or [[False|false]].
 
Condition is a [[Boolean]] expression that evaluates to [[True|true]] or [[False|false]].
Line 21: Line 21:
 
If you need two or more statements for true_statement or false_statement, place them within a [[Begin|begin]] ... [[End|end]] [[Block]].
 
If you need two or more statements for true_statement or false_statement, place them within a [[Begin|begin]] ... [[End|end]] [[Block]].
  
<delphi>
+
<syntaxhighlight>
 
   if boolean_condition then
 
   if boolean_condition then
 
     begin
 
     begin
Line 28: Line 28:
 
       statement_three;
 
       statement_three;
 
     end;
 
     end;
</delphi>
+
</syntaxhighlight>
  
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 15:36, 24 March 2012

English (en)

This keyword precedes a condition, is required to be followed by then and may optionally be followed by else.

If then

  if condition
    then true_statement
    else false_statement;

Condition is a Boolean expression that evaluates to true or false. true_statement is executed if condition evaluates to true. false_statement is executed if condition evaluates to false. An error occurs if condition does not evaluate to a boolean value.


More statements in "if then" statement

If you need two or more statements for true_statement or false_statement, place them within a begin ... end Block.

  if boolean_condition then
    begin
      statement_one;
      statement_two;
      statement_three;
    end;



Keywords: begindoelseendforifrepeatthenuntilwhile