samedi 27 juin 2015

Loop formatting

 - (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;
 }

For this code, why does nFactorial have to be initialized to n? Why can't the code just use n in all the places that have nFactorial in it?

Aucun commentaire:

Enregistrer un commentaire