In an if-statement why is 'return' used?
For example I have this, no return:
Then I reviewed this from danpost's barriers scenario:
private void stopWalking()
{
if (facingRight)
{
setImage (RMidle);
}
else
{
setImage (LMidle);
}
}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());
}


