extream newbie problem: Array index out of range
Monkey Forums/Monkey Beginners/extream newbie problem: Array index out of range
| ||
When i try to compile this code i get a "Array index out of range" error message but i can't find any errors in the code... it's driving me crazy. Function Main:Int () Local numbers:Int[] = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] For Local i:Int = 0 Until numbers.Length() Print(numbers[i]) End Return 0 End Function |
| ||
the console spits out this error message Monkey Runtime Error : Array index out of range C:/MonkeyX77a/Projects/Sandbox/test.monkey<16> |
| ||
I pushed the kill-button and recompiled and now it's working =D |
| ||
^^ |
| ||
That's strange... did you change anything else or the build target (release and debug)? Anyway if you didnt know you can also access the values of an array using EachIn: Local numbers:Int[] = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] For Local i:Int = Eachin numbers Print(i) End |
| ||
I don't know if it still happens, but there used to be a glitch where you could compile but a previous version would run (I think only HTML5 and/or Flash). So you could fix a bug and not see the fix. Or it might have been Just One Of Those Things. |
| ||
Oops .. Losing my mind. :) |
| ||
shouldnt it be For Local i:Int = 0 Until numbers.Length() - 1? As in your example array length is 11, but arrays start with index 0, so your doing a for loop from 0 to 11 ie 12 indexes. |
| ||
Until goes from start to max -1 To goes from start to max |