[Info-vax] decrementing & for loops in C

JF Mezei jfmezei.spamnot at vaxination.ca
Thu Jan 8 18:58:02 EST 2009


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.



More information about the Info-vax mailing list