Previous Icon 3

Next Icon 3

Functions

The different options for programming in functions are best described with the help of examples. A function's header looks like this:

// Transferred Variables of calling Program  
PAR Parameter1, Parameter2;  
 
// Declaration from Constants  
CONST PI=3.1415926, E=2.71828;  
 
// Declaration from local Variables  
VAR a,b,c,d;

 

Here, the lines that begin with // are comments. Each of these three lines may only occur once, and the declared variables must be separated with a comma. A non-initialized parameter or variable is VOID. This can be checked with ISVOID(variable).

Limited statements have two variants: IF or SWITCH statements:

   // IF statement with optional ELSIF and ELSE Block  
    IF Parameter1 > 5 THEN  
        a = sin(PI*Parameter1);  
    ELSIF Parameter1 < 0 THEN  
        a = Parameter1;  
    ELSE  
        a = 0;  
    ENDIF  
 
    // SWITCH Statement with Selection of figures or texts  
    SWITCH Parameter2  
    CASE 'Zero': b = 0;  
    CASE 'one': b = 1;  
    DEFAULT: b = 5;  
    ENDSWITCH

 

For loops, there are four program variants:

    // FOR Loop with optional intervals  
    FOR a = 1 TO 8 STEP 2 DO  
        b = b + a;  
        IF b>100 THEN  
            BREAK;      // Ends the Loop  
        ENDIF  
    NEXT  
 
    // WHILE Loop  
    WHILE b<100 DO  
        b = b*10;  
    WHEND  
 
    // DO Loop  
    DO  
        b = b*10;  
    UNTIL b>100;  
 
    // FORALL Loop calls for all Elements of an an array  
    c = [1,2,3,4,5,6,7,8,9];  
    a = 0;  
    FORALL c d DO   // d receives each of the Value of an an element from c  
        a = a + d;  
    NEXT

 

There is a special syntax for calling up functions that belong to objects. The standard method is to specify the object name followed by a point and the name of the function. However, the name of an object can also be contained in a local variable. This enables you to change the object for the function call at runtime.

    // The Function function calls for for object.  
    Object1.OBJ_GetMember('variablenname');  
 
    // a is a local Variable of Type String with the the of an object  
    a = 'Object1';  
 
    // This calls a Service function for called hierarchically superior with the a a  
    b = a.OBJ_GetMember('variablenname');  
 
    // calls a of User by Function for for Object1.  
    a.Userfunction();  
 
    // the of User by Function calls for called  
    // for the hierarchically superior object.  
    Userfunction();  
 
    // the of User by Function calls for called  
    // for the hierarchically superior object.  
    ^.UserFunction();

 

The system searches for variable names relatively to the current object. If object.z is used in an expression, the system will first attempt to find this variable below the current object. If it is not present, the search will continue in the hierarchically superior object (in accordance with ^.object.z) and so on.