Jordan Frampton
Jordan Frampton

Reputation: 1

is there a way to shorten if statement

Is there a better way to type the if statement

if( x > rah || y > rah|| x < 0 || y < 0) 

as this looks untidy and perhaps requires more computation than is needed

Upvotes: 0

Views: 84

Answers (1)

ergonaut
ergonaut

Reputation: 7057

It may look untidy, you could do this:

if (!between(x, 0, rah) || !between(y, 0, rah))

however, if you're thinking about excessive computations, you should order your conditions in order of likelihood to take advantage of the short-circuit operator ||. This is the only way to actually reduce computations.

Upvotes: 1

Related Questions