Else – Creating additional If-Conditions

Every case-branch is enclosed in an block, at a block end also the execution of the block ends, there is no implicit fall-through carried out, a fall-through is not even available. Only one else branch is allowed, it is hit in case no other branch was executed.

Example code:

1  rule example{
2   
3    n:N;
// we assume attributes a:int, arr:array<int>, narr:array<N>
4    
5      modify{
6        eval{
7          if(n.a < 42){
8            while(true){
9              n.a = n.a + 1;
10             if(n.a == 42) {
11               break; // leaves the while loop, n.a==42 afterwards
12             }
13           }
14         } else {
15             def ref narr:array<N> = n.narr;
16             def var i:int = 0;
17             for(tn:N in narr){
18               i = i + 1;
19               n.a = n.a + tn.a + n.arr[i];
20             }
21         }
22       }
23     }
24 }

More Examples can be found in these Packages:

BoM – Kit

Was this article helpful?

Related Articles