讓我們說數字= 0和otherNumber = 10.循環將執行。但是,如果number = 10和otherNumber = 0呢?我希望編譯器選擇最小的數字並使用它繼續。如何比較兩個數字並選擇最小值以繼續執行?
我到目前爲止的代碼是在這裏:
- (NSString *) stringWithNumbersBetweenNumber:(NSInteger)number andOtherNumber: (NSInteger)otherNumber {
if (number <= otherNumber) {
NSMutableString *indices = [NSMutableString stringWithCapacity:1];
for (NSInteger i= number; i <= otherNumber; i++) {
[indices appendFormat:@"%d", i];
}
} else {
NSMutableString *indices = [NSMutableString stringWithCapacity:1];
for (NSInteger i= otherNumber; i <= number; i++) {
[indices appendFormat:@"%d", i];
}
}
return @"%@", indices;
}
要清楚,你想一個循環,從最小變爲最大的兩個數的'號碼和'otherNumber'? – rmaddy