[Info-vax] decrementing & for loops in C

Bill Gunshannon billg999 at cs.uofs.edu
Fri Jan 9 08:50:12 EST 2009


In article <00529d50$0$4687$c3e8da3 at news.astraweb.com>,
	JF Mezei <jfmezei.spamnot at vaxination.ca> writes:
> Ed Vogel wrote:
> 
>> This depends upon what you mean by "correct".  Sure, it's
>> valid syntax, but it may not do what the user intended.
> 
> One can argue that C is quite logical about this.
> 
> a = b   is, in all cases, an assignment operator, even in conditional
> statements.
> 
> a == b  is, in all cases, a conditional operator.
> 
> There are some languages where a = b  can mean different things
> depending on context. (assignement, or conditional or whatever else)
> 
> And there are valid uses for a assignment operator in a for loop:
> 
> i = 1;
> for ( x == 0, n = i, x++ )
> 	{
> 	printf("%d\n", x)
> 	if ( x is not prime number, then i = 0)
> 	}
> 
> aka, a loop that increments X until some strange condition is reached.
> Yeah, you could just have "i" in there instead of n = i.

In which case this is not a for-loop condition at all and you should have
used something like while.  For loops are designed for specific kinds of
conditions.  Other methodds of iteration exist.  use the right tool for
the job.  There are way too many people claiming to be programmers who
have no legitimate claim to that title. (Sadly, many of them even claim
to eb "Software Engineers")

bill

-- 
Bill Gunshannon          |  de-moc-ra-cy (di mok' ra see) n.  Three wolves
billg999 at cs.scranton.edu |  and a sheep voting on what's for dinner.
University of Scranton   |
Scranton, Pennsylvania   |         #include <std.disclaimer.h>   



More information about the Info-vax mailing list