Skip to main content
Skip table of contents

Breaking and returning

ASTER provides three operators to alter loop and function execution. They require one right side parameter that is used as the function/loop return value.

RETURN

RETURN(x) # or RETURN x

This expression breaks the current function flow, returning immediately and using the provided X as the function return value.

Example

CODE
B=10; C=-1; D=-1; IX=-1;
X=5;

DEFUN("A","x",
    C=WHILE(x>=3, x=x-1;RETURN(7);B=15;x);    # note that B=15 is not executed
                                              # also the assignment to C was not executed
    IX = x;                                   # also not executed
    D=20;                                     # also not executed
    C                                         # also not executed
);

"F:"&A(x) & " B:" & B & " C:" & C & " D:" & D & " IX:" & IX

# Evaluates to F:7 B:10 C:1- D:1- IX:1-

# IX, D and C are not during the function execution, 
# due to RETURN breaking the function execution

# Function returns 7, as instructed by the parameter 7 given to RETURN

BREAK

BREAK(x) # or BREAK x

This expression breaks the current loop execution (FOR or WHILE) immediately and returns control to just before the loop, using the provided X as the loop return value.

Example

CODE
B=10; C=-1; D=-1; IX=-1;
X=5;

DEFUN("A","x",
    C=WHILE(x>=3, x=x-1;BREAK(x);B=15;x);     # note that B=15 is not executed
                                              # C was assigned to 
    IX = x;                                   # execution resumes here
    D=20;
    C
);

"F:"&A(x) & " B:" & B & " C:" & C & " D:" & D & " IX:" & IX  

# Evaluates to F:4 B:10 C:4 D:20 IX:4

# IX, D and C are altered during the normal function execution

# Loop returns 4, as when it enters at X = 5, it decrements and uses 
# the decremented value as argument to BREAK, which exits the loop at once

CONTINUE

CONTINUE(x) # or CONTINUE x

This expression jumps over the rest of current loop execution (FOR or WHILE) immediately and returns control to the loop controls, using the provided X as the loop return value.

Specifically for the FOR loop, the increment step will also be executed when using CONTINUE

Example

CODE
B=10; C=-1; D=-1; IX=-1;
X=5;

DEFUN("A","x",
    C=WHILE(x>=3, x=x-1;CONTINUE(x);B=15;x);  # note that B=15 is not executed
                                              # C was assigned to 
    IX = x;                                   # execution resumes here
    D=20;
    C
);

"F:"&A(x) & " B:" & B & " C:" & C & " D:" & D & " IX:" & IX   

# Evaluates to F:2 B:10 C:2 D:20 IX:2

# IX, D and C are altered during the normal function execution

# Loop returns 2, as when it enters at X = 3, it decrements and uses 
# the decremented value as argument to final CONTINUE exiting the loop
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.