If I want to use a loop like
for (NSUInteger row = 10; row >= 0; row--) {
// do something
}
how do I get around the fact that row will always be > 0 since it’s an unsigned integer. Does the middle construct of the for loop just become:
for (NSUInteger row = 10; row; row--) {
}
If you use NSInteger instead of NSUInteger this gets a bit simpler. Because NSInteger is a signed integer type, calling the decrement operator (
--) on a variable with the value zero changes the value to -1, so you can test for this using a simple comparison:If you have to use an NSUInteger for some reason then calling the decrement operator on a variable with a value of zero will result in the variable’s value wrapping around to the maximum possible value for NSUInteger. You can test for this using
NSUIntegerMax.