Control Statements

Some statements serve to control the process of the program.

All control statements can be grouped into the following categories:

Conditional Statements

These statements serve to branch out the process of the program.

If Statement

On the basis of the Condition value this statement decides whether the Statement should be executed. If the Condition is true, Statement is executed. If it is false, the Statement is ignored and process continues next after the if statement. Statement is either simple statement or a block of statements

  • if (Condition) Statement
    

Unlike the previous version of the if statement (in which the Statementis executed only if the Condition is true), other Statements that should be executed even if the Condition value is false can be added to the if statement. Thus, if the Condition is true, Statement1 is executed, if it is false, Statement2 is executed. See below:

  • if (Condition) Statement1 else Statement2
    

The Statement2 can even be another if statement and also with else branch:

  • if (Condition1) Statement1 
        else if (Condition2) Statement3
             else Statement4
    
Switch Statement

Sometimes you would have very complicated statement if you created the statement of more branched out if statement. In such a case, much more better is to use the switch statement.

Now, the Condition is evaluated and according to the value of the Expression you can branch out the process. If the value of Expression is equal to the the value of the Expression1, the Statement1 are executed. The same is valid for the other Expression : Statement pairs. But, if the value of Expression does not equal to none of the Expression1,...,ExpressionN, nothing is done and the process jumps over the switch statement. And, if the value of Expression is equal to the the values of more ExpressionK, more StatementK (for different K) are executed.

  • switch (Expression) {
        case Expression1 : Statement1
        case Expression2 : Statement2
        ...
        case ExpressionN : StatementN
    }
    

In the following case, even if the value of Expression does not equal to the values of the Expression1,...,ExpressionN, StatementN+1 is executed.

  • switch (Expression) {
        case Expression1 : Statement1
        case Expression2 : Statement2
        ...
        case ExpressionN : StatementN
        default:StatementN+1
    }
    

If the value of the Expression in the header of the switch function is equal to the the values of more Expressions# in its body, each Expression# value will be compared to the Expression value continuously and corresponding Statements for which the values of Expression and Expression# equal to each other will be executed one after another. However, if you want that only one Statement# should be executed for some Expression# value, you should put a break statement at the end of the block of statements that follow all or at least some of the following expressions: case Expression#

The result could look like this:

  • switch (Expression) {
        case Expression1 : {Statement1; break;}
        case Expression2 : {Statement2; break;}
        ...
        case ExpressionN : {StatementN; break;}
        default:StatementN+1
    }
    

Iteration Statements

These iteration statements repeat some processes during which some inner Statements are executed cyclically until the Condition that limits the execution cycle becomes false or they are executed for all values of the same data type.

For Loop

First, the Initialization is set up, after that, the Condition is evaluated and if its value is true, the Statement is executed and finally the Iteration is made.

During the next cycle of the loop, the Condition is evaluated again and if it is true, Statement is executed and Iteration is made. This way the process repeats until the Condition becomes false. Then the loop is terminated and the process continues with the other part of the program.

If the Condition is false at the beginning, the process jumps over the Statement out of the loop.

  • for (Initialization;Condition;Iteration) {
        Statement
    }
    
Do-While Loop

First, the Statement is executed, then the process depends on the value of Condition. If its value is true, the Statement is executed again and then the Condition is evaluated again and the subprocess either continues (if it is true again) or stops and jumps to the next or higher level subprocesses (if it is false). Since the Condition is at the end of the loop, even if it is false at the beginning of the subprocess, the Statement is executed at least once.

  • do {
        Statement
    } while (Condition)
    
While Loop

This process depends on the value of Condition. If its value is true, the Statements is executed and then the Condition is evaluated again and the subprocess either continues (if it is true again) or stops and jumps to the next or higher level subprocesses (if it is false). Since the Condition is at the start of the loop, if it is false at the beginning of the subprocess, the Statements is not executed at all and the loop is jumped over.

  • while (Condition) {
        Statement
    }
    
For-Each Loop

The foreach statement is executed on all fields of the same data type within a container. Its syntax is as follows:

  • foreach (variable : iterableVariable) {
        Statement
    }
    

All elements of the same data type (data type is declared for the variable at the beginning of the transformation code) are searched in the iterableVariable container. The iterableVariable can be a list, a map, or a record. For each variable of the same data type, specified Statement is executed. It can be either a simple statement or a block of statements.

Thus, for example, the same Statement can be executed for all string fields of a record, etc.

Jump Statements

Sometimes you need to control the process in a different way than by decision based on the Condition value. To do that, you have the following options:

Break Statement

If you want to stop some subprocess, you can use the following word in the program:

  • break
    

The subprocess breaks and the process jumps to the higher level or to the next Statements.

Continue Statement

If you want to stop some iteration subprocess, you can use the following word in the program:

  • continue
    

The subprocess breaks and the process jumps to the next iteration step.

Return Statement

In the functions you can use the return word either alone or along with an expression. (See the following two options below.) The return statement must be at the end of the function. If it were not at the end, all of the variableDeclarations, Statements and Mappings located after it would be ignored and skipped. The whole function both without the return word and with the return word alone returns null, whereas the function with the return expression returns the value of the expression.

  • return
    
  • return expression