none
what 's the difference between {return} and {break}? what's the conditon needed to use continue and break? RRS feed

  • Question

  • what 's the difference between {return} and {break}? what's the conditon needed to use continue and break?
    can someone give a help?
    Thursday, July 9, 2009 8:02 AM

Answers

  • Hi,

    Return will get you out of the function, break will get you out of the looping condition. For example


    void SomeFunc()
    {

         // lots of code

        for( i=0; i<n; ++i )
        {
             if( some condition )
                 return;

             // code, not executed if return called
        }

       // lots of code - this will not get executed if return is called
    }



    void SomeFunc()
    {

         // lots of code

        for( i=0; i<n; ++i )
        {
             if( some condition )
                 break;

             // code, this will not execute if break is called
        }

       // lots of code - this *will* get executed if break is called
    }
    Thursday, July 9, 2009 8:36 AM