Skip to content
the poor coder

advpl array

Poor Man
Published
Reading time
2 min read
On this page

What is AdvPL Array?#

AdvPL Array is a data type used in the AdvPL language for handling arrays. Arrays are a collection of data elements that are of the same data type, and each element can be accessed using an index number. AdvPL arrays can be one-dimensional, two-dimensional or multidimensional.

Creating an AdvPL Array#

To create an AdvPL array, you need to declare it with a name and specify the number of elements in the array. Here's an example of how you can create a one-dimensional array with three elements:

ADVPL

user : array(3)

You can also initialize the values of the array elements when you declare it. Here's an example of how you can create a one-dimensional array with three elements and initialize the values:

ADVPL

user : array(3) {"John", "Mary", "Peter"}

Accessing AdvPL Array Elements#

You can access individual elements of an AdvPL array using the index number. The index starts from 1 for the first element, 2 for the second and so on. Here's an example of how you can access the second element of a one-dimensional array:

ADVPL

user : array(3) {"John", "Mary", "Peter"}

// Accessing the second element
? user[2]
// Output: Mary

You can also use loops to access all elements of an AdvPL array. Here's an example of how you can use a for loop to iterate through all elements of a one-dimensional array:

ADVPL

user : array(3) {"John", "Mary", "Peter"}

for i := 1 to len(user)
    ? user[i]
next
// Output: John Mary Peter

AdvPL Multidimensional Array#

You can create multidimensional arrays in AdvPL by specifying the number of elements in each dimension. Here's an example of how you can create a two-dimensional array with three rows and two columns:

ADVPL

matrix : array(3,2)

You can access the elements of a multidimensional array using the index numbers of each dimension. Here's an example of how you can access the element in the second row and first column of a two-dimensional array:

ADVPL

matrix : array(3,2)

// Assigning a value to the element in the second row and first column
matrix[2,1] := "X"

// Accessing the element in the second row and first column
? matrix[2,1]
// Output: X

You can use nested loops to iterate through all elements of a multidimensional array. Here's an example of how you can use nested loops to iterate through all elements of a two-dimensional array:

ADVPL

matrix : array(3,2)

// Initializing the values of the elements
for i := 1 to len(matrix)
    for j := 1 to len(matrix[1])
        matrix[i,j] := i + "-" + j
    next
next

// Accessing all elements
for i := 1 to len(matrix)
    for j := 1 to len(matrix[1])
        ? matrix[i,j]
    next
next
// Output: 1-1 1-2 2-1 2-2 3-1 3-2

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC