For loop bug
-
Found a strange "for loop" bug when going from i=0 to -1 with a step -1.
// as expected, prints nothing for i=0 to 0 step -1 loop print(i, "\n") repeat print("Start B\n") // very inconsistently, prints both 0 and -1 for i=0 to -1 step -1 loop print(i, "\n") repeat loop update() repeat
ID: 56XK7MDN5
-
i don't think it's a bug as it goes until -1 -1 so actually -2
it does endvalue -1But it is indeed weird with the 1st one. it probably does some calulcations with start value and end value. And having both the same might have an influence. (like it checks if startval and endval are the same if so do nothing) I try to not use for loops with negative steps. If i need it i use a while
-
But a similar for loop going from i=0 to 1 prints 0 and not 1.
print("Start C\n") // prints both 0 and 1 for i=0 to 1 loop print(i, "\n") repeat
-
@Chronos it starts on 0 if you had 10 it would be 9
-
I know, I'm stating that to demonstrate the inconsistency in the loops' behaviors. The problem loop is from 0 to -1 including -1.
-
@Chronos oh I see wish I could help
-
This post is deleted!