Developing Apama Applications > Developing Apama Applications in EPL > Defining What Happens When Matching Events Are Found > Defining conditional logic
Defining conditional logic
EPL supports conditional if-then and if-then-else statements.
Syntactically an if-then statement consists of an if keyword followed by a boolean expression followed by a then keyword followed by a block. A block consists of one or more statements enclosed in curly braces, {}. If the boolean expression is true the contents of the block are executed. If the expression is false, the if-then statement exits.
The boolean expression must evaluate to the boolean values true or false.
An if-then-else consists of if followed by a boolean expression followed by then followed by a ‘then’ block followed by an else keyword followed by an ‘else’ block. If the boolean expression is true, the first block is executed, otherwise the second block is executed.
There is a special variant of the if-then-else allowed where a second nested if-then or if-then-else statement can replace the second block. This is only of relevance in that no curly braces are required in this special case.
In standard BNF notation this syntactic definition looks as follows:
ifStatement ::= if booleanExpression then block    
| if booleanExpression then block1 else block2    
| if booleanExpression then block3 else ifStatement block ::= {statementList }
Note: BNF is an acronym for "Backus Naur Form". John Backus and Peter Naur introduced for the first time a formal notation to describe the syntax of a given language in 1960, and since then BNF notation is the standard notation used to specify the syntax rules of programming languages.
An EPL example follows:
if floatVariable > 5.0 then {
integerVariable := 1;
} else if floatVariable < -5.0 then {
      integerVariable := -1;
} else {
      integerVariable := 0;
}
Note that if-then-else statements can be nested. In other words, the body of a then or an else can contain another if-then-else, in addition to the explicit else if combination.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.