Reputation: 43
How can I shorten this nested if statement?
if(x > 0){
if(grid[x-pixelOffset,y] == true){
middleLeft = 1;
}
}
Upvotes: 2
Views: 275
Reputation: 21
Just for more information, if short-circuit is not desired, you may use the &. If you write if( (x>0) & grid[x,y]) {...}, the second part will be evaluated too.
Upvotes: 2
Reputation: 726479
You can use the &&
operator:
if ((x > 0) && grid[x-pixelOffset,y])
...
You do not need == true
when you check values of bool
variables.
Upvotes: 5