I have:
NSDictionary* server;
for (server in self.servers)
{
if (<some criterium>)
{
break;
}
}
// If the criterium was never true, I want to use the last item in the
// the array. But turns out that `server` is `nil`.
The loop block never changes server
.
servers
is an NSMutableArray
with dictionaries, a property that's not changed during the loop.
Why does server
have the value nil
after the loop has ended?
Was the first time I used such a variable after the loop. Without thinking too much, I assumed it would work like (in the old C days):
int i;
for (i = 0; i < n; i++)
{
...
}