0

I would like to skip the remainder of a function and call another should a statement prove true.

public bool A(int i)
        {
            if (i > 5)
            {
                // Skip the rest of A() and return B()
                return B(i);
            }

            // Do stuff to i
        }

        public bool B(int i)
        {
            // Do stuff to i
        }

Is my only option to have the return value as a bool, even if I don't care what the boolean return value is?

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by caovan
Featured Replies
  • This is for when not wanting it to return anything. Notice that when returning nothing, it will just exit out of the method. [CODE] public void A(int i) { if (i > 5) { // Skip the rest of A() and return B() B(i); return; } // Do stuff to … Read More

1

This is for when not wanting it to return anything. Notice that when returning nothing, it will just exit out of the method.

public void A(int i)
        {
            if (i > 5)
            {
                // Skip the rest of A() and return B()
                B(i);
                return;
            }

            // Do stuff to i
        }

        public void B(int i)
        {
            // Do stuff to i
        }
0

Thank you. :)

Does this have any speed advtanges over returning bool?

Edited by DaveTran: n/a

0

Not really. You only want to use bool or anything returned if you will be doing logic on it later.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.