Lists
- Updated2025-10-31
- 2 minute(s) read
Use lists to save numeric values, texts, or PAscript objects of the same data type.
Introduced in PAtools 8.0
All elements of a list have the same data type. For certain variables, the list contains the value of a variable at the time the value was added. Those variables include numeric, text, and buffer variables.
Subsequently insert or remove new elements at any position. If necessary, the capacity of a list is automatically increased when you add new elements to the list.
Definition
Define lists according to the following scheme:
list<type> identifier
The type is one of the defined PAscript data types. Then, you can access the list under the identifier.
Access to the Elements of a List
- Directly using the list index.
- Iterating over the list elements with a loop. This loop processes all list elements. The loop automatically fills an iterator variable (or run variable) with the corresponding list element.
Direct Access to a List Element
Use the list index to directly access a list item.
type variable = listVariable[int32 position]
Example
Program list<int8> _list = [1,2,3,4,5] int8_result = _list[0] sys:logInfo(sys:ui, "result: %d", _result) // => result: 1 endprogram
Access Using foreach Loop
Use the foreach loop to iterate through the elements of a list.
foreach iteratorVariable in listVariable
// Code
// Optional: exit from the loop by means of break
endforeach
The iteratorVariable variable contains the value or reference to the current list element.
Example
Program
list<int8> _list = [1,2,3,4,5]
int8_iterVar, _result
foreach _iterVar in _list
_result = _result + _iterVar
endforeach
sys:logInfo(sys:ui, "result: %d", _result) // => result: 15
endprogram