Why doesnt this work?
if (condition) stuff; return;
else otherStuff;
or this
if (condition) stuff; return;
else {otherStuff;}
I can easily fix this with:
if (condition) {stuff; return;}
else otherStuff;
but I thought that the if statement block entire line not excluding return.
Because with:
The
ifconditional has a single statement,stuff.It’s followed by an unrelated
returnstatement.The
elseis stranded on its own, which isn’t legal Java.Semicolons are statement terminators, not EOLs. In order for a statement to be a block, it must be surrounded by
{}, otherwise the statement ends at the;.