I was just wondering if there is any way to get out of a Java block. It can be any block - if block, for block or even a simple {}. This is because I often come across such situations
{
retCode = performSomeThing();
if(retCode == SUCCESS)
{
retCode = performSomethingElse();
if(retCode == SUCCESS)
{
. . .
. . .
}
}
}
This multiple levels of indentation clutters up the code I write.
Instead I need some way to do this
if((retCode = performSomething()) != SUCCESS)
GET_OUT_OF_BLOCK
if((retCode = performSomethingElse()) != SUCCESS)
GET_OUT_OF_BLOCK
Based on the value of retCode I will perform any required processing outside the block. Would be nice if it doesn't involve writing that block within a try-catch block, creating a new exception type, throwing it and then catching it.