[Expression]Current iteration of loop

I’d like to request expression which would give current iteration of loop if it was executed in for…each, while, or repeat X times loop event. If it would be executed in normal event it would return -1.


Has this been considered? Using a variable and incrementing it seems a bit of extra work when there must be a [hidden?] system variable keeping track of the iteration.

It depends, in JavaScript there is two ways, the for in and the for of way. The for is in this format:

for (let i in objects) {
    // Access with index
    let object = objects[i];

As you see with this method you get the indice (variable I) and it would be possible indeed.
But the for of is used like this:

for (let object of objects) {

Is smaller and easier to understand. If this one is used we would need to convert to for in, and the use of this is discutable as it is possible already with variables.

It can’t be either way. Repeat is for a number of iterations, and that would make it for scenarios without reference to any objects.

If the underlying structure was a for ‘in’ or ‘of’, then it wouldn’t allow a repeat for x number of times without referring to an object type.

Yes it is possible.

for (let i in Array(6)){
    // Will be called 6 times

Sure it’s possible, but why have that as the underlying mechanism? That’d make the whole thing more convoluted than it needs to be. The repeat condition takes a numeric. It’d be simpler to have a for(i=0; i<x; i++) style controller. And if that were the case, then getting the value of i should be possible.