In an if-statement why is 'return' used?
For example I have this, no return:
Then I reviewed this from danpost's barriers scenario:
1 2 3 4 5 6 7 8 9 10 11 | private void stopWalking() { if (facingRight) { setImage (RMidle); } else { setImage (LMidle); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | if (getOneIntersectingObject(Barrier. class ) != null ) { if (dy == 0 ) { setLocation(getX(), getY() + 1 ); if (getOneIntersectingObject(Barrier. class ) == null ) return ; setLocation(getX(), getY() - 2 ); if (getOneIntersectingObject(Barrier. class ) == null ) return ; setLocation(getX() - dx, getY() + 1 ); return ; } setLocation(getX() - dx, getY()); } |