Is it possible to split / return method execution from another method?

I have something like this:

void MethodToBreak()
{
    // do something

    if(something)
    {
        MethodThatBreaks();
        return;
    }

    // do something
}

void MethodThatBreaks()
{
    // do something
}

So, I was wondering: is it possible to break the execution from MethodThatBreaks():? Then I would have:, if(something) MethodThatBreaks();and if the condition inside is iftrue, nothing after this line will be satisfied.

NOTE. I know that this is possible with elsein this case, but I do not want this.

+5
source share
3 answers

, . , , , .

, , else. , else? , , , , , .

+4

MethodThatBreaks . , MethodToBreak catch try.

0

You can do this: declare a global variable

 a=null;
void MethodToBreak()
{
    // do something

    if(something)
    {
        MethodThatBreaks();
        if(a==null){

        } else{
        return;
        }
    }

    // do something
}

void MethodThatBreaks()
{
     a="somevalue";
    // do something
}
-2
source

All Articles