A
Angus
Hello
My understanding is that the conditional expression in a for loop is
evaluated BEFORE each iteration. I understood this to mean that the
evaluation of a counter used would be BEFORE the counter is
incremented (or decremented or however changed).
But in my test code below:
for(; s < end; ++i)
this does not appear to be happening.
test code:
char start = 0;
char end = 0;
int i, j;
char s[27] = {0};
i=j=0;
start = 'A';
end = 'Z';
for(; s < end; ++i)
s = start + i;
I was expecting the char array s to be filled with A-Z and then stop.
ie in the test s < end, when s is Z (decimal 90) then end is
also Z (90) and so for loop should stop. But the for loop does NOT
stop.
If I try
for(; s[i-1] < end; ++i)
s = start + i;
Then the for loop does end at the correct point so I am assuming that
i is incremented before the test. Can someone please confirm what is
the expected behaviour.
Angus
My understanding is that the conditional expression in a for loop is
evaluated BEFORE each iteration. I understood this to mean that the
evaluation of a counter used would be BEFORE the counter is
incremented (or decremented or however changed).
But in my test code below:
for(; s < end; ++i)
this does not appear to be happening.
test code:
char start = 0;
char end = 0;
int i, j;
char s[27] = {0};
i=j=0;
start = 'A';
end = 'Z';
for(; s < end; ++i)
s = start + i;
I was expecting the char array s to be filled with A-Z and then stop.
ie in the test s < end, when s is Z (decimal 90) then end is
also Z (90) and so for loop should stop. But the for loop does NOT
stop.
If I try
for(; s[i-1] < end; ++i)
s = start + i;
Then the for loop does end at the correct point so I am assuming that
i is incremented before the test. Can someone please confirm what is
the expected behaviour.
Angus