If...Else...End if

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 6.0


The formal syntax of the If...Else...End if control flow structure is:

   If (Boolean_Expression)
      statements(s)
   Else
      statement(s)
   End if

Note that the Else part is optional; you can write:

   If (Boolean_Expression)
      statements(s)
   End if

The If...Else...End if structure lets your method choose between two actions, depending on whether a test (a Boolean expression) is TRUE or FALSE.

When the Boolean expression is TRUE, the statements immediately following the test are executed. If the Boolean expression is FALSE, the statements following the Else statement are executed. The Else statement is optional; if you omit Else, execution continues with the first statement (if any) following the End if.

Example

      ` Ask the user to enter the name
   $Find:=Request("Type a name:")   
   If (OK=1)
      QUERY([People]; [People]LastName=$Find)
   Else
      ALERT("You did not enter a name.")
   End if

Tip: Branching can be performed without statements to be executed in one case or the other. When developing an algorithm or a specialized application, nothing prevents you from writing:

   If (Boolean_Expression)
   Else
      statement(s)
   End if

or:

   If (Boolean_Expression)
      statements(s)
   Else
   End if

See Also

Case of...Else...End case, Control Flow, For...End for, Repeat...Until, While...End while.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next