Assigning values to array elements

LET statement can also be used to assign values to program array elements by listing the values after it. Such a way of value assignment may prove useful when there is no logical connection between the values of the elements (otherwise, the usage of conditional loops is more preferable).

 

This method is only applicable to one-dimensional arrays. If applied, all the array elements in the same LET statement should be listed, otherwise an error will occur. The values of the elements should be separated by commas:

DEFINE my_arr [3] of INTEGER

LET my_arr = 11, 56, 23654

In the case of multidimensional arrays (two or three dimensions) the values should be assigned separately for each element of an array. Please, consider the following example:

my_arr ARRAY [2,3] OF CHAR(15)

...

LET my_arr[1,1] = "One-one "

LET my_arr[1,2] = "One-two "

LET my_arr[1,3] = "One-three"

LET my_arr[2,1] = "Two-one"

LET my_arr[2,2] = "Two-Two"

LET my_arr[2,3] = "Two-three"

If you have an ARRAY of RECORD structure, you should keep to the following scheme of value assignment:

LET array_name[coordinate].record_member = value

LET rec_array[1].mem_1 = "Record value"

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.