Difference between revisions of "If and Then"

From Lazarus wiki
Jump to navigationJump to search
Line 1: Line 1:
 
This [[Keyword|keyword]] preciedes a condition, is required to be followed by [[Then|then]] and may be followed by [[Else|else]].
 
This [[Keyword|keyword]] preciedes a condition, is required to be followed by [[Then|then]] and may be followed by [[Else|else]].
 +
 +
== If then ==
  
 
<delphi>
 
<delphi>
Line 10: Line 12:
 
Action1 is executed if condition evaluates to true.
 
Action1 is executed if condition evaluates to true.
 
Action2 is executed if condition evaluates to false.
 
Action2 is executed if condition evaluates to false.
 +
 +
If you need two or more statements in "if then" statement. In that case, you need the [[Begin|begin]] ... [[End|end]] around the statements.
 +
 +
<delphi>
 +
  if boolean_condition then
 +
    begin
 +
      statement_one;
 +
      statement_two;
 +
      statement_three;
 +
    end;
 +
</delphi>
 +
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 18:15, 17 October 2007

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

If then

<delphi>

 if condition
   then action1
   else action2;

</delphi>

Condition is an expression that evaluates to true or false. Action1 is executed if condition evaluates to true. Action2 is executed if condition evaluates to false.

If you need two or more statements in "if then" statement. In that case, you need the begin ... end around the statements.

<delphi>

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

</delphi>



Keywords: begindoelseendforifrepeatthenuntilwhile