Re: for Loop Error or Logical Error?
Re: for Loop Error or Logical Error?
- Subject: Re: for Loop Error or Logical Error?
- From: James Bucanek <email@hidden>
- Date: Sun, 24 Dec 2006 09:03:25 -0700
Matthew Callis wrote on Sunday, December 24, 2006:
>Where is the error? Every time I go through it, it seems like it's as it
>should be based on my old Windows code. By adding weird OR additions with i
>== some number at the end it starts adding them, but it doesn't count them
>all or add up all the time.
I can't immediately see what's wrong with your loop (mostly because I'm not exactly sure what you're trying to do), but stepping through the debugger should certainly reveal the flaw. When you step through it, it will either step into the first part of the if statement or not. At the point in which the code branches to where it isn't suppose to go, examine the contents of the variables that got you there and work backwards.
One thing that seems *very* suspicious is that you pre-initialize all of the current... variables to [allTapes objectAtIndex:0] before you begin. Consequently, the first iteration through the loop will match the pre-selected current value and never output. These values should, more likely, be set to nil or some invalid value so the first object in the array will not match the current one and be output.
For several reasons (code efficiency, performance, readability, and just to save my fingers excess wear and tear), consider dereferencing some values. You execute the statement [allTapes objectAtIndex:i] about a billion times. I'd start my loop with
currentTape = [allTapes objectAtIndex:i];
and go from there.
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden