- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSInteger n = 5;
NSInteger nFactorial = n;
while (n > 1) {
nFactorial = nFactorial * --n;
}
NSLog(@"The factorial of %ld is %ld", (long)n, (long)nFactorial);
return YES;
}
对于此代码,为什么必须将nFactorial初始化为n?为什么代码只能在所有包含nFactorial的地方使用n?
答案 0 :(得分:0)
如果使用n
替换nFactorial
,则第二个nFactorial
的值不是我们的例外。