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

Access the elements of a list using one of the following methods:
  • 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]
Note The index of the first list entry is 0. Therefore, the value passed as position must be less than the number of list elements (0 ≤ position < list:count).

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
Note Calling the foreach loop returns valid list elements only. For example, you called the resize command to increase the list capacity. In this case, the list contains empty elements. These empty list elements are not written to the iterator variable.