If...Then...Else Statement

The If...Then...Else statement is fundamental to many programming languages. In Intent language, this statement can appear in several different forms.

In the most simple form, a statement block is executed when a boolean test expression is evaluated as True. The following example supplies the FootType rule with a value of :RoundFoot, if a parameter Load has a value less than 12.

If Load < 12 Then
   FootType = :RoundFoot
End If

By adding an Else clause to the statement, the If statement can execute a different statement block if the boolean test expression is evaluated as False.

If Load < 12 Then
   FootType = :RoundFoot
Else
   FootType = :SquareFoot
End If

Adding an ElseIf clause allows you to test multiple boolean expressions. There is no limit to the number of ElseIf clauses in an If statement. The optional Else clause will execute its statement block if none of the boolean test expressions evaluate as True.

If Load < 12 Then
   FootType = :RoundFoot
ElseIf Load < 100 Then
   FootType = :SquareFoot
Else
   FootType = :RoundTransitionFoot
End If

If Expression

If expression is a single line If...Then...Else expression that can be inserted anywhere that an expression is permitted. As an expression, it must always return a value. Therefore, an Else clause is required. If expressions must always be enclosed by parentheses.

The following example shows an If expression being used in a child rule. The child Foot will instantiate as either a :RoundFoot or :SquareFoot part, depending on the value of the Load parameter.

Child Foot As (If Load < 12 Then :RoundFoot Else :SquareFoot)
End Child