xHarbour Reference Documentation > Function Reference |
Returns the current ordinal position of a FOR EACH iteration.
HB_EnumIndex() --> nIteration
The function returns a numeric value. It is the ordinal position of the current item within a FOR EACH control structure.
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.
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 |
// 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
http://www.xHarbour.com