Logo

Programming-Idioms

History of Idiom 43 > diff from v60 to v61

Edit summary for version 61 by OC:
New Obj-C implementation by user [OC]

Version 60

2020-07-05, 20:32:22

Version 61

2020-10-11, 19:52:49

Idiom #43 Break outer loop

Look for a negative value v in 2D integer matrix m. Print it and stop searching.

Idiom #43 Break outer loop

Look for a negative value v in 2D integer matrix m. Print it and stop searching.

Variables
m
Variables
m
Imports
@import Foundation;
Code
[m enumerateObjectsUsingBlock:^(NSArray *row, NSUInteger rn, BOOL *stopr) {
  [row enumerateObjectsUsingBlock:^(NSNumber *v, NSUInteger cn, BOOL *stopc) {
    if (v.intValue<0) {
      NSLog(@"found %@ at row:%lu col:%lu",v,rn,cn);
      *stopr=*stopc=YES;
      return; // to quit the current block immediately
    }
  }];
}];
Comments bubble
Showing an imperfect work-around with blocks. If blocks are not used, goto is available: check the plain C idiom for an example. Note it might be tempting to use exceptions instead; do not: in ObjC it is considered a bad practice