xHarbour Reference Documentation > Function Reference |
Evaluates a code block for each array element.
AEval( <aArray>, <bBlock>, [<nStart>], [<nCount>] ) --> aArray
The function returns a reference to <aArray>.
The array function AEval() traverses an array beginning with the element <nStart> and passes the values of individual array elements to the code block <bBlock>. The code block is evaluated and AEval() proceeds to the next array element until either <nCount> elements are processed or the end of the array is reached. The return value of the code block is ignored.
With each iteration, the code block receives as parameters the value stored in the current array element and a numeric value indicating the ordinal position of the current array element.
Note that AEval() is appropriate for iterating an array once. Operations that require a more sophisticated iteration or that alter array elements are programmed in FOR...NEXT or FOR EACH loops.
See also: | DbEval(), Eval(), FOR, FOR EACH, HEval(), QOut() | QQOut() |
Category: | Array functions , Code block functions |
Source: | vm\arrayshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The first part of the example displays the contents of an array while the // second part first increases the value of the elements and then displays it // on the screen. PROCEDURE Main() LOCAL aArray := {"A", "B", "C", "D", "E", "F" } ? "Simple iteration: " AEval( aArray, {|x| QQOut(x) } ) // result: ABCDEF ? "Fill array with consecutive numbers: " AEval( aArray, {|x,n| aArray[n] := n } ) // Note: LOCAL variable is visible within code block // since aArray and code block are created in the // same procedure. AEval( aArray, {|x| QQOut(LTrim(Str(x))) } ) // result: 123456 RETURN
http://www.xHarbour.com