Support

        Equilla Quick Start

Equilla Loops

Loops serve to call functions multiple times without having to enter the function code again and again. This is especially useful in cases in which the number of necessary runs for the loop is calculated during program execution. 

In this chapter, all loop types available in Equilla are described.

For all Equilla operators, you can find additional information in Tradesignal. To display it, open the source code in the Equilla Editor. Then right-click on the operator in question, e.g. Begin, and choose Lookup Equilla Function from the context menu. A window opens with information on the operators and links to related functions.


Loops with a definite number of cycles (For...To...Do)

For this type of loop, start and end values are given. The number of cycles is given by their difference. 

//This loop repeats the command 10 times
For counter = 0 to 9 Do
    command;

//This loop repeats the block of commands 10 times
For counter = 0 to 9 Do
    Begin
        command1;
        command2;
        ...
        commandX;
    End;

You also have the option to rule with which steps the loop have to run. The standard for the step is 1. 

//This loop repeats the command 5 times
For counter = 0 to 9 Step 2 Do
    command;
    
//This loop repeats the command 10 times with a negative incrementation
For counter = 9 to 0 Step -1 Do
    Print(Counter);

You also have the option to give the start and end value of the loop as variables. This way, the loop is more flexible and results of partial calculations or functions can be used as counters.

//This loop repeats the command 13 times
Variables: 
    startCount( 0 ), endCount( 12 );

For counter = startCount to endCount Do
    command;

//This loop repeats the block of commands 13 times
For counter = startCount to endCount Do
    Begin
        command1;
        command2;
        ...
        commandX;
    End;

Condition-controlled Loops

The above presented type of loop uses a fixed value as a counter for the number of cycles. The values can be set by variables, but these variables cannot be changed from within the loop. However, this is necessary in cases, for example, in which the number of cycles depends on the result of a calculation within the loop itself. 

For these cases, other types of loops exist. These loops run until a certain result or value in the cycle meets a certain condition. There are two different subtypes of these loops:

Loop with the condition before the execution (While...Do)

The condition for the loop is checked before the loop is executed. 

//This loop runs 10 times ( 0-9 )
Variables: 
    counter(10), sumCounter(0);

While ( counter < sumCounter ) Do
    sumCounter = sumCounter + 1;


//You can also run several commands as a block. 
Variables: 
    counter(10), sumCounter(0);

While ( counter < sumCounter ) Do
    Begin
        sumCounter = sumCounter + 1;
        Print( sumCounter );
    End;


Loops with the condition after the execution (Repeat...Until)

The condition for the loop is checked after each cycle run, i.e. after the calculation. 

//This loop runs 10 times ( 0-9 )
Variables: 
    counter(10), sumCounter(0);

Repeat
    sumCounter = sumCounter + 1;
Until ( sumCounter < counter );


//You can also run several commands as a block. 
Variables: 
    counter(10), sumCounter(0);

Repeat
    Begin
        sumCounter = sumCounter + 1;
        Print( sumCounter );
    End;
Until ( sumCounter < counter );

 

BACK TO OVERVIEW      Equilla Conditions