I am looping through an array but I am having some trouble at first and last items in the array. 

The code compares `arr[i]` with `arr[i+1]` and `arr[i-1]`. Obviously I want the index to compare `i-1` as the last element but this causes an out of bound array index.

Current Loop:

```
     (i=1; i<arr.size-1; i++) 

    if (arr(i-1,0)==2 || arr(i+1,0)==2)
    {
        do stuff
    }

```

It only works if `i` starts at `i=1` and loops to `arr.size-1`. How can I get around this?