condition - Objective C: -1 < 0 return false -


is there difference between 2?

int count = 0; (uiview *view in scrollview.subviews) {     nslog(@"%d < %d", [json[@"images"] count] - 1, count);     // output: -1 < 0     if ([json[@"images"] count] - 1 < count) break; } 

and

int count = 0, maxindex = [json[@"images"] count] - 1; (uiview *view in scrollview.subviews) {     nslog(@"%d < %d", maxindex, count);     // output: -1 < 0     if (maxindex < count) break; } 

what i've facing was, first solution didn't break loop, whereas second solution did.

is there reason behind?

thats because count nsuinteger property. therefore never -1 in case.and in second case you're assigning maxindex int, gives -1.

so try understand whats happening.

int count = 0; nsuinteger maxindex = [json[@"images"] count] - 1; (uiview *view in scrollview.subviews) { nslog(@"%d < %d", maxindex, count); // output: -1 < 0 if (maxindex < count) break;  //this not break either maxindex never `-1` 

}

also,in nslog using %d format specifier type int , try %lu or %lx

hope helps


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -