PDA

Click to See Complete Forum and Search --> : if statement


Academy
Nov 5th, 2006, 10:41 PM
is the following if statement valid?

if(0< maze[point.x][point.y] && maze[point.x][point.y] <= 5)

I wanted to say the array is greater than zero and equals to or less than 5.

Thanks!

TBeck
Nov 5th, 2006, 11:37 PM
logically it should work, the && operator requires that both boolean statements must be true. Are you having troubles with it in your code or getting errors?

Academy
Nov 5th, 2006, 11:55 PM
I tried to run the program and it gives me an error "ArrayIndexOutOfBoundsException -1".

TBeck
Nov 6th, 2006, 12:01 AM
it probably has to do with a loop around the if statement, if you post more of the code around the if statement i could take a look at it and see if i can tell what it is doing.

CornedBee
Nov 6th, 2006, 03:43 AM
I wanted to say the array is greater than zero and equals to or less than 5.

You can't compare an array to a scalar. What your code does is:
"If the value at the index pair (point.x, point.y) of the 2d array 'maze' is greater than 0 and less than or equal to 5"

But apparently the index pair (point.x, point.y) is out of bounds for the array.

AlnavPlatinum
Nov 6th, 2006, 01:18 PM
I've found the problem. CornedBee is right, the pair of my coordinate(x,y) is out of bounds. At first, I thought it was the problem with the if statement.

Thanks.