Objective-C: `continue` in collection enumeration block?

hzxu picture hzxu · Nov 9, 2012 · Viewed 10.8k times · Source

If I have an NSArray and I use enumerateUsingBlock to loop through elements in the array, but in some cases I need to skip the loop body and go to next element, is there any continue equivalent in block, or can I use continue directly?

Thanks!

update:

Just want to clarify, what I want to do is:

for (int i = 0 ; i < 10 ; i++)
{
    if (i == 5)
    {
        continue;
    }
    // do something with i
}

what I need is the continue equivalent in block.

Answer

AntonPalich picture AntonPalich · Nov 9, 2012

A block is a lot like an anonymous function. So you can use

return

to exit from the function with return type void.