About FOR EACH

96 views
Skip to first unread message

Luigi Ferraris

unread,
Mar 12, 2026, 1:18:14 PM (3 days ago) Mar 12
to Harbour Users
Hi friends,
is there a way to set beginning in FOR EACH statement?
Example: array := { "a", "b", "c" }
FOR EACH item IN array FROM 2
or setting an internal __beginPos ?

Many thanks in advance.
Best Regards
Luigi

Maurizio la Cecilia

unread,
Mar 12, 2026, 2:22:49 PM (3 days ago) Mar 12
to harbou...@googlegroups.com
Hi Luigi,
please take a look to <hbroot>\tests\foreach2.prg

Best regards.
--
Maurizio
Luigi --
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/6d2550bd-9580-4281-af9b-d9cc340d5289n%40googlegroups.com.


Luigi Ferraris

unread,
Mar 13, 2026, 1:25:11 PM (2 days ago) Mar 13
to Harbour Users
Hi Maurizio, sorry for delay and thanks.

I looked at the source, but it's a "for each" implementation inside a class.

My desire was like this:
LOCAL arry := { "1", "2", "3", "4" }
LOCAL item
FOR EACH item IN arry FROM 2 
In other words, to start from the 2 element and discards the first.

Take a look next code
FOR iK := 2 TO LEN(array)

Best regards.
Luigi

Maurizio la Cecilia

unread,
Mar 13, 2026, 4:09:18 PM (2 days ago) Mar 13
to Harbour User Group
Ok, I was aware of your desire...
However, if you don't want to use a class, a trick could be:

procedure main()
local item
for each item in { "1", "2", "3", "4" }
    if item:__enumIndex() >= 2
       ? item:__enumIndex(), "=>", item
       // insert your code here
    endif
next
inkey(0)
// or, avoiding a dummy cycle
// until the start is reached:
for each item in { "1", "2", "3", "4" }
    if item:__enumIndex() < 2
        item:__enumIndex( 2 )
    endif
    ? item:__enumIndex(), "=>", item
    // insert your code here
next
inkey(0)

Best regards.
--
Maurizio
Mostra testo citato


Reply all
Reply to author
Forward
0 new messages