xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_EnumIndex()

Returns the current ordinal position of a FOR EACH iteration.

Syntax

HB_EnumIndex() --> nIteration

Return

The function returns a numeric value. It is the ordinal position of the current item within a FOR EACH control structure.

Description

Function HB_EnumIndex() is only used within a FOR EACH control structure. It returns a numeric value which can be viewed as the "loop counter" of the FOR EACH statement. HB_EnumIndex() identifies the ordinal position of the item that is currently processed by FOR EACH.

Info

See also:FOR, FOR EACH, HB_QSelf(), HB_QWith()
Category: Control structures , Environment functions , xHarbour extensions
Source:vm\hvm.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example compares a regular FOR..NEXT loop with a
// FOR EACH loop. FOR..NEXT uses a loop counter while FOR EACH
// does not. Instead, the "loop counter" is retrieved with
// function HB_EnumIndex().

   PROCEDURE Main
      LOCAL aArray1 := { "A", "B", "C" }
      LOCAL aArray2 := { "a", "b", "c" }
      LOCAL i, cValue

      CLS

      ? "FOR loop"

      FOR i:=1 TO Len( aArray1 )
         ? i, aArray1[i]

         IF i == 3
            AAdd( aArray1, "D" )
         ENDIF
      NEXT

      ?
      ? "FOR EACH loop"

      FOR EACH cValue IN aArray2
         ? HB_EnumIndex(), cValue

         IF HB_EnumIndex() == 3
            AAdd( aArray2, "d" )
         ENDIF
      NEXT
   RETURN

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