Re: Annoying warning: statement with no effect
Re: Annoying warning: statement with no effect
- Subject: Re: Annoying warning: statement with no effect
- From: Steve Bird <email@hidden>
- Date: Mon, 11 Nov 2002 17:03:21 -0500
On Monday, November 11, 2002, at 02:39 PM, Jonathan Jackel wrote:
Several of the for loops in my projects are generating a compiler
warning
stating "statement with no effect". But the statements all have
effects and
behave as intended. For instance:
for (r = [addRowsField intValue]; r--; r == 0)
[self createNewPoint];
This statement works exactly as you would expect. The variable r
starts
with the number in a field, decrements with each loop, and stops when r
reaches zero.
Anyone else seen this? What's the cure?
You, sir, are one lucky dog.
The SECOND expression is the test for loop termination.
The THIRD expression is usually the inc/dec expression.
In your case, the "r--" is being interpreted as "r-- != 0", which means
it will be true until r reaches 0, which is exactly what you want.
In your case, the third expression has no effect - the loop code tests
if r==0 every time thru, but does nothing with the answer.
Swap expressions 2 and 3
----------------------------------------------------------------
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
www.Culverson.com (toll free) 1-877-676-8175
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.