A
Anony!
Hi
I realize that using breaks in code is not recommended and should be
avoided. However, I have a situation where it cannot be avoided.
<snippet>
public String aMethod()
{
for (...)
{
if (...)
{
//some processing 1
break;
}
if (...)
{
//some processing 2
}
}
return result;
}
I tried to put the return statement where the break statement is hoping that
it would terminate further processing and return the result. But the compile
complains that nothing is returned. That makes sense because the return
statement needs to be at the end. Therefore I have to make use of the break
to get out of the loop and then return the result.
AaA
I realize that using breaks in code is not recommended and should be
avoided. However, I have a situation where it cannot be avoided.
<snippet>
public String aMethod()
{
for (...)
{
if (...)
{
//some processing 1
break;
}
if (...)
{
//some processing 2
}
}
return result;
}
I tried to put the return statement where the break statement is hoping that
it would terminate further processing and return the result. But the compile
complains that nothing is returned. That makes sense because the return
statement needs to be at the end. Therefore I have to make use of the break
to get out of the loop and then return the result.
AaA