A While statement is a Turbo Integrator function which follows the same logic as the While function found in other forms of scripts. When a condition given is true, the While statement executes in a loop until the condition is no longer true.
How to implement a while statement:
- Set up while logic
- Add the statement / condition
- End the statement
In the following example, a While statement is used to run through elements and identify ones with a specific number:
Objective: Create a subset which is populated by the last period in a year.
To achieve this, you can use while statement to run through all elements in a month period and find the ones with ‘12’ at the string end.
The steps will be:
- Define Dimension and create the subset
vDim = ‘DB.Month’;
- Get the dimension element number:
nEleNum = DimSiz(vDimension);
- Set up while logic: While number of elements is bigger than 0,
While(nEleNum > 0);
- Condition or action, here you can put any condition to select on which element to be actioned. You can return the element name by DimNm Function and insert to the subset the ones which has ‘12’ at the 5th and 6th string in its name.
sEle = DimNm(vDim, nEleNum);
vEle = sEle;
- Loop command. After the initial script has been actioned, command the process to find next element. If dimsiz return with 256 elements (nEleNum), the first loop will be actioned on 256th then you can tell it to process the one before by subtracting it by 1
nEleNum = nEleNum-1;
- Terminate while statement when the condition is met (nElenum =0)