# For loop changes

**URL:** <https://es.discourse.group/t/for-loop-changes/239>\
**Category:** 💡 Ideas\
**Created:** [February 25, 2020, 3:27am UTC](https://es.discourse.group/t/for-loop-changes/239 "2020-02-25T03:27:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnini](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mnini/32/253_2.png) [@mnini](https://es.discourse.group/u/mnini)\
**Post date:** [February 25, 2020, 3:27am UTC](https://es.discourse.group/t/for-loop-changes/239/1 "2020-02-25T03:27:06Z")

</div>

`for( number )`  
Does number repeats of a loop.  
`for( number as i )`  
Increments from 0 to number.

Actually workings of for of, for in, and this fors could be without brackets, they don't serve to separate language function as the paranthesis or end of token serve for that here.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [February 25, 2020, 4:40am UTC](https://es.discourse.group/t/for-loop-changes/239/2 "2020-02-25T04:40:13Z")

</div>

What if `number` is not an integer? What if it's negative? What if it's NaN, or Infinity? What if it's a BigInt, or a proposed Decimal?

---

<div class="post-metadata">

**Author:** ![michael](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/michael/32/11_2.png) [@michael](https://es.discourse.group/u/michael)\
**Post date:** [February 26, 2020, 2:42am UTC](https://es.discourse.group/t/for-loop-changes/239/3 "2020-02-26T02:42:06Z")

</div>

This sounds like the syntax equivalent of [the Number.range proposal](https://github.com/Jack-Works/proposal-Number.range). I would strongly prefer an API-based solution for creating sequences of numbers.

---

<div class="post-metadata">

**Author:** ![mnini](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mnini/32/253_2.png) [@mnini](https://es.discourse.group/u/mnini)\
**Post date:** [February 28, 2020, 4:35pm UTC](https://es.discourse.group/t/for-loop-changes/239/4 "2020-02-28T16:35:31Z")

</div>

I highly doubt somebody would put number that is not integer as i in for loop.

But maybe 'by' keyword could identify the increment by steps...

---

<div class="post-metadata">

**Author:** ![mnini](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mnini/32/253_2.png) [@mnini](https://es.discourse.group/u/mnini)\
**Post date:** [February 28, 2020, 4:36pm UTC](https://es.discourse.group/t/for-loop-changes/239/5 "2020-02-28T16:36:32Z")

</div>

No it doesn't ... range creates array, this is proposal for having sugar for i in for loop.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [February 28, 2020, 4:46pm UTC](https://es.discourse.group/t/for-loop-changes/239/6 "2020-02-28T16:46:16Z")

</div>

If it is possible, somebody will do it, so the spec would have to define behavior for it.

---

<div class="post-metadata">

**Author:** ![michael](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/michael/32/11_2.png) [@michael](https://es.discourse.group/u/michael)\
**Post date:** [February 28, 2020, 4:50pm UTC](https://es.discourse.group/t/for-loop-changes/239/7 "2020-02-28T16:50:10Z")

</div>

No, it produces an iterator, which can be used in a for-of loop just like you want.

---

<div class="post-metadata">

**Author:** ![mnini](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mnini/32/253_2.png) [@mnini](https://es.discourse.group/u/mnini)\
**Post date:** [February 28, 2020, 5:00pm UTC](https://es.discourse.group/t/for-loop-changes/239/8 "2020-02-28T17:00:00Z")

</div>

Well, so it does produces iterator, but for \>of\< range is not quite good...

loop(5) or for(4) sounds better.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [February 28, 2020, 5:13pm UTC](https://es.discourse.group/t/for-loop-changes/239/9 "2020-02-28T17:13:38Z")

</div>

If for value of array sounds good, then for value of range does too, imo.

---

<div class="post-metadata">

**Author:** ![JackWorks](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jackworks/32/260_2.png) [@JackWorks](https://es.discourse.group/u/JackWorks)\
**Post date:** [March 1, 2020, 10:34am UTC](https://es.discourse.group/t/for-loop-changes/239/10 "2020-03-01T10:34:32Z")

</div>

Is there any of your use case doesn't get covered by the range proposal?

---

<div class="post-metadata">

**Author:** ![mnini](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mnini/32/253_2.png) [@mnini](https://es.discourse.group/u/mnini)\
**Post date:** [March 3, 2020, 10:21pm UTC](https://es.discourse.group/t/for-loop-changes/239/11 "2020-03-03T22:21:49Z")

</div>

Maybe the possibility not writing range proposal...

range function which returns iterator is something you don't have to implement, because well, iterator interface is here for that, here I argue for the possibility of not writing range at all.

---

<div class="post-metadata">

**Author:** ![kevinbarabash](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kevinbarabash/32/560_2.png) [@kevinbarabash](https://es.discourse.group/u/kevinbarabash)\
**Post date:** [December 29, 2020, 9:23pm UTC](https://es.discourse.group/t/for-loop-changes/239/12 "2020-12-29T21:23:01Z")

</div>

I experimented with using iterators for this in the past, but have ended up using the basic `for(let i = 0; i < n; i++)` loop because I was worried about performance. If there was a standard iterator for ranges then browsers or tooling such as babel could optimize them.
