Conditions and flow control

From FlexRule Wiki
Jump to: navigation, search

These commands are related to Procedural logic.


Generally in a procedural approach you may come across a situation where you need to compare values. Based on that comparison, you need to carry out a task or decision. In situations where comparison is required, If command can be used.

For example, the following command checks whether the age of a person is less than 18 years:

  1. <If condition="person.Age  lt 18">
  2.     <!-- Action comes here -->
  3. </If>

In condition part of If an Expression is expected.

Branching Multiple Conditions

There is also the possibility of having nested If(s), and if their conditions are mutually exclusive (they cannot be all true), then you can use the ElseIf command instead. For the exclusion part of the chain of conditions Else may be used.

  1. <If condition="person.Age  lt 18">
  2.     <!-- Action comes here -->
  4.     <ElseIf condition="person.IsMale">
  5.         <!-- Action for this condition -->
  6.     </ElseIf>
  8.     <ElseIf condition="person.IsFemale">
  9.         <!-- Action for this condition -->
  10.     </ElseIf>
  12.     <Else>
  13.         <!-- Default action -->
  14.     </Else>
  15. </If>

Please note ElseIf and If/Else should be covered by an initial condition using If.