Control Flow

The following keywords are used for controlling the execution flow in the APL programming language.

KeywordDescriptionExample
breakTerminates the execution of the current loop. 
while(i++ < 10) { 
 if( i == 5 ) {
   break; 
 }
}
continueTerminates execution of the current iteration of the loop, and continues execution of the next iteration. 
while( i++ < 10) {
 if( i%2 == 0 
  //your code
 {
else {
 continue; }
 }
}
for

for loop (for-each loop):

The for loop is used to iterate through a list's elements in a first-to-last order. This type of loop only consists of a variable declaration and a list type. The declared variable, which is only available in the scope of the for loop, is assigned an element in each iteration.

for loop (advanced):

Creates a loop that consists of three expressions.

The first expression performs the initialization of a variable used for counting iterations. A variable declared in this expression is only available in the scope of the for loop.

The second expression contains a condition that must evaluate to true or false. The loop iterates until the condition evaluates to false.

The third expression is evaluated at the end of each loop iteration, before the next evaluation of the condition. This is typically used to update or increment the counting variable in the condition. 


list<int> listOfInts =   listCreate(int,1,2,3);
for (int i: listOfInts) { 
 //your code
}
 
list<string> listOfStrings = listCreate(string,"1","2","3");
for (string s: listOfStrings) { 
 //your code
}
for( int i=0; i<10; i++ ) { 
//your code
}
if elseUsed to execute code with conditions.
if (myVar == "ABC") {// do_this} else {// do_that}
returnStops the execution of the current function block.
if ( ANumber == null ) { return;}
while

Loops while a condition is true.

Note!

If the APL code generates an infinity loop it can be stopped by, in the Workflow Monitor or Execution Manager, selecting the Stop button and Stop Immediate. This will however not  wor if the loop is running in the initialize or deinitialize blocks.

while( i < 20 ) { // do_stuff}



switch case

Allows an expression to be tested for equality against a list of values or types, where each of these is a case.

The cases are evaluated against the variable in order, from top to bottom. After a match, the remaining cases will not be evaluated.

Testing values:

The value for a case must be the same data type as in the switch expression.

Testing types:

The type for a case must be followed by a variable declaration as shown in the example column.

A switch statement can have an optional default case, else, which must appear at the end of the switch. The default case can be used for performing a task when the variable does not match any of the other cases.

//Testing values
switch (str) {
	case "one" { debug("One"); }
	case "two" { debug("Two"); }
 	else debug("other");
}
 
//Testing types
switch (input) {
	case (PulseUDR p){
		debug(p.Sequence); 
	}
	case (MyUDR m) {
		debug(m.aField); 
	}
}

//Testing container types

switch (value) {

case (map<any, any> m) {

debug("This is a map.");

 }

case (list<any> l){

debug("This is a list.");

}

}