0

Hi everybody, I'm just wondering what is the more eficient and compact way to write statements like this

if(site.next(1) == null) {
      return false;
}
if(site.next(2) == null) {
      return false;
}
if(site.next(3) == null) {
      return false;
}
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by shean1488
1
  1. You can combine multiple tests in one if, in this case ORing them together, as in
    if ( site.next(1) == null || site.next(2) == null ...

  2. The contents of the if must be a boolean expression, so you don't need an if to turn that into a booelan result, eg
    return ! ( site.next(1) == null || site.next(2) == null

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.