#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int p, isPrime, d;
p = 2;
while (p <= 50){
isPrime = 1;
++p;
for (d = 2; d< p; ++d)
if ( p% d == 0 )
isPrime = 0;
if (isPrime != 0)
NSLog (@"%i", p);
}
// insert code here...
//NSLog(@"Hello, World!");
[pool drain];
return 0;
}
run
[Switching to process 4489]
Running…
2010-05-06 23:43:03.299 6.10[4489:80f] 3
2010-05-06 23:43:03.303 6.10[4489:80f] 5
2010-05-06 23:43:03.304 6.10[4489:80f] 7
2010-05-06 23:43:03.305 6.10[4489:80f] 11
2010-05-06 23:43:03.306 6.10[4489:80f] 13
2010-05-06 23:43:03.307 6.10[4489:80f] 17
2010-05-06 23:43:03.309 6.10[4489:80f] 19
2010-05-06 23:43:03.310 6.10[4489:80f] 23
2010-05-06 23:43:03.311 6.10[4489:80f] 29
2010-05-06 23:43:03.312 6.10[4489:80f] 31
2010-05-06 23:43:03.312 6.10[4489:80f] 37
2010-05-06 23:43:03.315 6.10[4489:80f] 41
2010-05-06 23:43:03.316 6.10[4489:80f] 43
2010-05-06 23:43:03.316 6.10[4489:80f] 47
Debugger stopped.
Program exited with status value:0.
I was playing around with the prgm in the book. why doesn't the number 2 show what did i do wrong in the while construct?