Results 1 to 6 of 6

Thread: if statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    108

    if statement

    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!

  2. #2
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: if statement

    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?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    108

    Re: if statement

    I tried to run the program and it gives me an error "ArrayIndexOutOfBoundsException -1".

  4. #4
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: if statement

    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.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: if statement

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Lively Member
    Join Date
    May 2002
    Posts
    118

    Re: if statement

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width