Suggestion: for-of-and loops

# Brian Blakely (10 years ago)

Apologies if this isn't the correct forum for this, and please point me the right way if not.

The motivation is that it would be useful if one could tersely loop over multiple iterators simultaneously. I think this could be accomplished with a "for-of-and" syntax.

Example:

let temp = [80, 35, 20];

let cond = ['sunny', 'cloudy'];

for(let [t, c] of temp and cond) { console.log(t, c); // first: 80 'sunny' // second: 35 'cloudy' // third: 20 undefined }

As above, this is useful when we have two separate but related data sets. It becomes more powerful as the data sets become more complex.

Example:

let forecast1 = [ { "highTemp": "90", "lowTemp": "70" }, { "highTemp": "92", "lowTemp": "82" }, // etc... ];

let forecast2 = [ { "high": "85", "low": "68", "condition": "partiallycloudy" }, { "high": "95", "low": "80", "condition": "sunny" }, // etc... ];

for(let [f1, f2] of forecast1 and forecast2) { console.log(average(f1.highTemp, f2.high)); }

Thanks for reading!

# Kevin Smith (10 years ago)

Have you tried writing a combinator which does exactly that? Take a look at zip in python.

# Brian Blakely (10 years ago)

That is basically what I have done in practice.

# Brendan Eich (10 years ago)

Kevin Smith wrote:

Have you tried writing a combinator which does exactly that? Take a look at zip in python.

Right -- we don't add new syntax lightly, we'd need to see zip used a lot, and at some irreducible-without-special-form overhead.

# Brian Blakely (10 years ago)

Thank you for that insight