Search code examples
objective-ciosnsarrayobjective-c-blocks

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


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.


Solution

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

    return

    to exit from the function with return type void.