xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

AEval()

Evaluates a code block for each array element.

Syntax

AEval( <aArray>, <bBlock>, [<nStart>], [<nCount>] ) --> aArray

Arguments

<aArray>
This is the array to iterate.
<bBlock>
The code block evaluated for the elements of <aArray>. It receives two parameters: the value of the current array element and its numeric position in the array.
<nStart>
This is a numeric expression indicating the first element in the array to begin with. It defaults to 1, the first element of <aArray>.
<nCount>
A numeric expression specifying the number of elements to pass to the code block. It defaults to 1+Len(<aArray>)-<nStart>.

Return

The function returns a reference to <aArray>.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe