C# – How to exit from a using statement

c++

I am trying to exit from a using statement while staying in an enclosing for loop. eg.

 for (int i = _from; i <= _to; i++)
 {

    try
    {

        using (TransactionScope scope = new TransactionScope())
        {
            if (condition is true)
            {
                // I want to quit the using clause and
                // go to line marked //x below
                // using break or return drop me to line //y
                // outside of the for loop.
            }

        }

    } //x
}
//y

I have tried using break which spits me out at //y, however I want to remain in the for loop at //x so the for loop continues to process. I know that I can do it by throwing an exception and using a catch but I'd rather not do this relatively expensive operation if there is a more elegant way to break out of the using. Thanks!

Best Solution

Skip the using completely:

if (condition is false)
{
    using (TransactionScope scope = new TransactionScope())
    {
....