# For loop issue

**URL:** https://talk.remobjects.com/t/for-loop-issue/15349
**Category:** Silver
**Created:** [January 25, 2018, 7:38am UTC](https://talk.remobjects.com/t/for-loop-issue/15349 "2018-01-25T07:38:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ndelic](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ndelic/32/526_2.png) [@ndelic](https://talk.remobjects.com/u/ndelic)
#### Post date: [January 25, 2018, 7:38am UTC](https://talk.remobjects.com/t/for-loop-issue/15349/1 "2018-01-25T07:38:45Z")

</div>

This loop in [Silver.NET](http://Silver.NET):

```
for i in (0..<3) {
}

```

loops from 0 to 3, but should go from 0 to 2. Right?

This one:

```
for i in (0..2) {
}

```

will go from 0 to 1.

Doesn’t make sense, should be vice versa.

Using VS2015 with the latest Elements 9.3 stable release.

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [January 25, 2018, 9:30am UTC](https://talk.remobjects.com/t/for-loop-issue/15349/2 "2018-01-25T09:30:36Z")

</div>

thanks! fixed

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [January 26, 2018, 11:27am UTC](https://talk.remobjects.com/t/for-loop-issue/15349/3 "2018-01-26T11:27:21Z")

</div>

Actually; I fixed this but my fix was completely wrong. The output seems fine?

```auto
import System.Collections.Generic
import System.Linq
import System.Text
import System.Threading.Tasks

print("The magic happens here.")

for i in (0..<3) {
    writeLn(i);
}

for i in (0...2) {
    writeLn(i);
}

print("")

```

```auto
The magic happens here.
0
1
2
0
1
2

```

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 26, 2018, 2:36pm UTC](https://talk.remobjects.com/t/for-loop-issue/15349/4 "2018-01-26T14:36:32Z")

</div>

hmm I get

```auto
~> Process ConsoleApplication221 started.
The magic happens here.
loop a: 0
loop a: 1
loop a: 2
loop a: 3
loop b: 0
loop b: 1

~> Process ConsoleApplication221 terminated with exit code 0

```

for

```auto
import System.Collections.Generic
import System.Linq
import System.Text

print("The magic happens here.")

for i in (0..<3) {
	writeLn("loop a: "+i);
}

for i in (0...2) {
	writeLn("loop b: "+i);
}

```

so it does indeed seem broken.

(note to OP, `..` isn’t valid, only `...` is?)

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [January 26, 2018, 2:37pm UTC](https://talk.remobjects.com/t/for-loop-issue/15349/5 "2018-01-26T14:37:49Z")

</div>

Thanks, logged as bugs://79436

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [January 26, 2018, 2:39pm UTC](https://talk.remobjects.com/t/for-loop-issue/15349/6 "2018-01-26T14:39:00Z")

</div>

bugs://79436 got closed with status fixed.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 26, 2018, 3:06pm UTC](https://talk.remobjects.com/t/for-loop-issue/15349/7 "2018-01-26T15:06:29Z")

</div>

Turns out the problem was with the Range type. `for I in 0...2` would use an optimized for/to loop, and work, `for I in (0...2)` with parenthesis used the Range type, which was broken. Fixed for today’s upcoming beta in SBL. Workaround is to nit use parenthesis, or to grab latest SBL form GitHub.
