The operator in is a binary operator used in an elementary logical expression that has the following format:
An item used as a subscript of an array can not itself be an array element. In each of the following examples, myItemB[1] is both a subscript and an array element; as a result, the following syntax is not valid:
/* the next syntax is not valid */ myItemA[myItemB[1]] // this next syntax is not valid; but only // because myItemB is myItemB[1], the // first element of a one-dimensional array myItemA[myItemB]
In relation to both one-dimensional and multidimensional arrays, the search ends at the last element of the one-dimensional array under review.
If the elementary logical expression resolves to true, the operation in sets the system variable sysVar.arrayIndex to the subscript value of the element that contains the search value. If the expression resolves to false, the operation sets sysVar.arrayIndex to zero.
structureItem name="myString" length=3 structureItem name="myArray" occurs=3 length=1
The next table shows the effect of the operator in if myString is "ABC".
Logical expression | Value of expression | Value of sysVar. ArrayIndex | Comment |
---|---|---|---|
"A" in myArray | true | 1 | The subscript of a single-dimension array defaults to 1 |
"C" in myArray[2] | true | 3 | Search begins at second element |
"A" in myArray[2] | false | 0 | The search ends at the last element |
structureItem name="myArray01D" occurs=3 length=3 structureItem name="myArray02D" occurs=3 length=1
In this example, myArray01D is a one-dimensional array, with each element containing a string that is substructured to an array of three characters. myArray02D is a two-dimensional array, with each element (such as myArray02D[1,1]) containing a single character.
"A" "B" "C" "D" "E" "F" "G" "H" "I"
The next table shows the effect of the operator in.
Logical expression | Value of expression | Value of sysVar. ArrayIndex | Comment |
---|---|---|---|
"DEF" in myArray01D | true | 2 | A reference to a one-dimensional array does not require a subscript; by default, the search begins at the first element |
"C" in myArray02D[1] | — | — | The expression is invalid because a reference to a multidimensional array must include a subscript for each dimension |
"I" in myArray02D[3,2] | true | 3 | Search begins at the third row, second element |
"G" in myArray02D[3,2] | false | 0 | Search ends at the last element of the row being reviewed |
"G" in myArray02D[2,4] | false | 0 | The second subscript is greater than the number of columns available to search |
Related tasks
Syntax diagram for EGL statements and commands
Related reference
Arrays
Logical expressions
Operators and precedence
arrayIndex