checking if im still in the array
Monkey Forums/Monkey Beginners/checking if im still in the array
| ||
i have to deal with allot of array's and i want to check if my operation landed me outside the array. i try to do checking for Null but i get compile error that null isnt an int or null isnt float |
| ||
Post an.example and we'll be able to help much better |
| ||
Like this?Strict Function Main:Int() Local myArray:Int[] = New Int[20] Print "Number of elements :" + myArray.Length For Local i:Int = 0 Until myArray.Length '<<< from 0 to the last array element (exclusive) Print myArray[i] Next Local x:Int = 20 If x < myArray.Length Then ' Check if the index x is within the array bounds Print "Inside!" Else Print "Outside" EndIf Return 0 End |
| ||
|
| ||
Checking for null won't work. There is nothing at a non-existent array element, not even null! Acccessing it should give a runtime error. Check that the array index is within the array Length(s). If that's too inefficient and you want to do fake 'pointer arithmetic' with indexes. put guard values at the edges and test for them. (Or find an algorithm that will never go outside the array.) |
| ||
ok im using an aditional array to put all the array's size's in, that kinda work. thx |