On May 2, 2020, at 1:10 AM, Aparajita Fishman via 4D_Tech 
<4d_tech@lists.4d.com> wrote:
> 
>> "Don’t be so quick to complain; you finally got ‘for each’ 10 years after
>> the rest of the world (including Active4D).”
>> Good point. So…you’re thinking that the feature set is complete?
> 
> Absolutely. In fact it is more complete than most implementations, you can 
> specify and begin and end index for ordered collections.

Since both collection and entity selections support .slice(), I’ve wondered why 
the begin/end index parameters exist on For each. 

>> it’s funny that we have such a handy looping construct yet I have write code 
>> to init and update my own index.
> 
> If you need an index in a ‘for each’ loop, you should actually be using an 
> indexed ‘for’ loop. That’s the point of having ‘for each’ separate from 
> ‘for’: 90% of the time you don’t need the index and ‘for each’ is more 
> concise, but when you need an index a for loop increments it for you.

In 4D, when enumerating collections or entity selections, about half the time I 
want an index for progress calculation, and other times I have to use the 
indexed for loop because I want to early exit. 

For other languages, providing the index on enumeration varies by language and 
enumeration construct, but most have an enumeration construct that provides an 
index. Almost all support break.

So 4D’s implementation could be considered more redundant, less 
feature-complete. If an index were provided instead of start/end, and you could 
set that index to .length to exit the loop, we’d pretty much never have to use 
an indexed loop for a collection or entity selection.

Jim Crate

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to