Question: I have the function below:

```
- (void)doStuff {
    BOOL allDoneNow = NO;
    for (int i = 0; i < [arABFBmatches count]; i++) {
        for (int j = 0; j < [arABFBmatches count]; j++) {
            if (should_skip_rest) {
                allDoneNow = YES;
                break;
            }
        }
        if (allDoneNow) break;
    }
}

```

Now, if I call that method with `[self doStuff];`, how can I detect if the function broke? Or is there a better way to stop and restart the execution of a function?

Answer: 
```
- (BOOL)doStuff // <- return a boolean value
{
  for (int i = 0; i < [arABFBmatches count]; i++) 
  {
    for (int j = 0; j < [arABFBmatches count]; j++) 
    {
      if (should_skip_rest) 
      {
        return NO;   // <- NO for break
      }
    }
  }
  return YES; // <- YES for completed
}

```

This beaks the execution of the function. If you want to restart it, simply call it in a `while` loop.

```
while( (doStuff()==NO) && thereShouldBeAnotherConditionForStopping )
{
  // Do something after each attempt, otherwise it seems to be a little bit silly
}

```
Or you can use blocks, like this:

```
- (void)doStuff:(void (^)())breakBlock{
    BOOL allDoneNow = NO;
    for (int i = 0; i < [arABFBmatches count]; i++) {
        for (int j = 0; j < [arABFBmatches count]; j++) {
            if (should_skip_rest) {
                allDoneNow = YES;
                breakBlock();
                break;
            }
        }
        if (allDoneNow) breakBlock();
    }
}

```

and call it: 

```
[self doStuff:^{
    NSLog(@"ends with break");
}];

```