ID:168437
 
mob/verb/Test()
for(var/x=1, x<=5, x++)
x-=2


That gives me an infinite loop, which it obviously should.

mob/verb/Test()
for(var/x=1 to 5)
x-=2


That doesn't give me an infinite loop. Once the loop completes once, x is restored to whatever it should be rather than taking in account the x-=2.

I somehow doubt this is a bug, but can someone explain why this happens? It just caused me 2 hours of pain.
Ok..... Well it isnt a bug. Well basically this is what is happening. You define x and set it to 1. Then if it is smaller than 5 (which it is) it exucutes the statement which is taking 2 away from it. So now x is -1. Then it runs x++ which adds 1 to x which will equal 0. So x will never be 5 or over as you are taking 1 away every loop.

<font color=red><font size=5>ADT_CLONE</font></font>
In response to ADT_CLONE
I think you missed the entire point of my post.

for(var/x=1, x<=5, x++) - Gives an infinite loop.
for(var/x=1 to 5) - Doesn't give an infinite loop.
In response to DeathAwaitsU
I didnt even know for(var/x=1 to 5) or whatever you put was valid. I dont know what it does.
In response to ADT_CLONE
the reson is you can not modify the value x perintly.
Test()
for(var/x=1 to 5)
x-=2


so first line for(var/x=1 to 5) x=1
next line x will = -1
then gos back to firs line and rembers that x was 1 before and so makes it 2

every thim this loops you loos your changes to the variable
In response to The Riddler
I know that it does that (After about 2 hours of frustration) but what puzzles me is why you can modify x in for(var/x=1,x<=5,x++) but not in for(var/x=1 to 5)?
In response to DeathAwaitsU
Because the first loop is more "manual" and directly modifies the vars. The second loop is a bit more like looping through a list - like for(var/x in list(1,2,3,4,5)) - in which case the current value of x doesn't affect which cycle the loop is up to.
DeathAwaitsU wrote:
I somehow doubt this is a bug, but can someone explain why this happens? It just caused me 2 hours of pain.

Yes, I can explain it. The syntax for(x=1 to 5) is equivalent in BYOND to this:
for(x in list(1,2,3,4,5))

x is always being set to the next item in the list regardless of its present value.

Lummox JR