[Info-vax] decrementing & for loops in C

Jim Duff spam.this at 127.0.0.1
Thu Jan 8 14:06:22 EST 2009


vaxinf at chemie.uni-konstanz.de wrote:
> Hi,
> 
> I tried to run one of the example found on Jim Duff's homepage and
> found a behavior of for loops written in C:
> 
> int main (void) {
> 
> int i,sum=0,n=10;
> 
>     (void)printf ("Starting countdown loop...\n");
>     (void)fflush (stdout);
>     for (i = n; i = 0; i--) {
>         (void)printf (" i: %i\n",i);
>     }
>     (void)printf ("done.\n");
> 
>     (void)printf ("Starting normal loop...\n");
>     (void)fflush (stdout);
>     for (i = 1; i <= n; i++) {
>         (void)printf (" i: %i\n",i);
>     }
>     (void)printf ("done.\n");
> }
> 
> Here is the output:
> 
> r SYSWRITE_TST
> Starting countdown loop...
> done.
> Starting normal loop...
>  i: 1
>  i: 2
>  i: 3
>  i: 4
>  i: 5
>  i: 6
>  i: 7
>  i: 8
>  i: 9
>  i: 10
> done.
> 
> So the countdown loop is ignored. g++ under linux behaves the same.
> 
> Are there any references that one cannot use decrementation and for
> loop in C?
> 
> regards
> Eberhard

Umm, which of my examples contains the erroneous loop?  I have no doubt
that I would never write:

int i,sum=0,n=10;

I would write:

static int i;
static int sum = 0;
static int n = 10;

so I doubt the above code is anything I wrote.

Unfortunately, my webhost is having problems with PHP at the moment, and
the examples are not displaying correctly, but I have searched the
example codebase and can find no reference to "countdown".

Jim.
-- 
www.eight-cubed.com



More information about the Info-vax mailing list