+ 25
{Tips for Java} Using return with if statement.
Whenever you have a return statement inside an if statement, you do not need to provide an else clause. If an if statement condition is false, the code execution continues after the block. If the statement is true, the method execution will finish with the return statement. if (condition) { // code == true return valueIfTrue; } // code == false return valueIfFalse;
3 Answers
+ 15
@Hitesh to reduce indentation caused by else use return that was what I meant to say.
+ 2
thanks mate, this one really helped me out
+ 1
you can use break statement then code execution is stop in if block. try it.