Skip to content

for loop unexpected behavior #4889

@shamil-ru

Description

@shamil-ru

Hi,

I am trying to run this simple script:

N = 1

for i in [0..N]
  console.log 'i = ' + i
  for j in [(i+1)..N]
    console.log 'j = ' + j

And I get:

i = 0
j = 1
i = 1
j = 2
j = 1

If I add by 1 to the second loop:

N = 1

for i in [0..N]
  console.log 'i = ' + i
  for j in [(i+1)..N] by 1
    console.log 'j = ' + j

... then I get:

i = 0
j = 1
i = 1
j = 2

Is this behavior adequate? Why is j equal to 2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions