# 记录一次 不确定多层for循环的写法

2016/10/14 14:25

- (void)cyle {
_resultsArray = [NSMutableArray array];
_dataArray = @[@[@"1",@"2",@"3"],
@[@"4",@"5",@"6",@"*"],
@[@"7",@"8",@"9"]];
[self cyle:0 dataArr:_dataArray[0]];
NSLog(@"%@",_resultsArray);
}
/*
* @param count 循环层数
* @param arr 每次循环数据数组
*/
- (void)cyle:(NSInteger)count dataArr:(NSArray *)arr {
if (count == 0) {
} else {
NSMutableArray * tempArray = [NSMutableArray array];
for (NSInteger i = 0; i < _resultsArray.count; i++) {
for (NSInteger j = 0; j < arr.count; j++) {
}
}
[_resultsArray removeAllObjects];
_resultsArray = tempArray;
}
count++;
if (count >= _dataArray.count) {
return;
}
[self cyle:count dataArr:_dataArray[count]];
}

/*

"1-4-7",
"1-4-8",
"1-4-9",
"1-5-7",
"1-5-8",
"1-5-9",
"1-6-7",
"1-6-8",
"1-6-9",
"1-*-7",
"1-*-8",
"1-*-9",
"2-4-7",
"2-4-8",
"2-4-9",
"2-5-7",
"2-5-8",
"2-5-9",
"2-6-7",
"2-6-8",
"2-6-9",
"2-*-7",
"2-*-8",
"2-*-9",
"3-4-7",
"3-4-8",
"3-4-9",
"3-5-7",
"3-5-8",
"3-5-9",
"3-6-7",
"3-6-8",
"3-6-9",
"3-*-7",
"3-*-8",
"3-*-9"
*/

0
0 收藏

0 评论
0 收藏
0