When the follow code is run it goes inside the for loop and run NSLog. Why does this happen?
NSString *aString = nil;
for (int i=0; i<([aString length]-2); i++) {
NSLog(@"Inside loop.");
}
As i figure [aString length]-2 results in -2 and that’s less then 0?
To be more precise,
-[NSString length]returns an unsigned integer, so subtracting two from zero (remember, calling any method onnilgives you zero) doesn’t give you -2, it gives you a very, very large number. Cast it to anint(or anNSInteger) to get the results you want.