【发布时间】:2015-07-08 19:20:14
【问题描述】:
我想检查两个 for 循环是否返回匹配项,如果它们什么也没发生,但如果它们不执行,我希望打印一条消息,说明“找不到匹配项”之类的信息。像这样的:
if (loop1 == 0 && loop2 == 0) {
NSLog(@"A match could not be found, please check your spelling");
};
因此,我的问题是,如何描述循环以便检查它们给出的值?
这是循环:
for (SMADoc *aSearch in docs) {
if ([search isEqualToString:[aSearch leadAuthour]]) {
//Open the file that is represented by UrlToDoc for that specific object
[[NSWorkspace sharedWorkspace] openFile:[aSearch urlToDoc]];
}
}
} else {
//The string starts with a number and should be converted to an int and then the array of the numbers should be searched through
int number = atoi(searchC);
NSNumber *sNumber = [NSNumber numberWithInt:number];
for (SMADoc *nSearch in docs) {
if ([sNumber isEqualToNumber:[nSearch docNumber]]) {
[[NSWorkspace sharedWorkspace] openFile:[nSearch urlToDoc]];
}
}
}
提前致谢!
【问题讨论】:
-
这真是令人困惑。您似乎错过了一些
if声明。loop1和loop2是什么?您到底想在这里和哪里检查什么? -
@rmaddy
loop1和loop2只是为了描述我的想法,上面的代码不是完整的程序,只是我发现相关的部分。实际上,我自己设法解决了这个问题,并将解决方案作为对@vadian 答案的评论发布在下面。不过谢谢你的帮助!
标签: objective-c loops for-loop