>> for (x = 0, ffcounter = 0; x < bytes.length; x++)
>> {
[quoted text clipped - 17 lines]
> me, Algol people will likely agree. It is a matter of creating least
> surprise.
Did I miss something? The original posting did not create the variable
inside the for loop.
> 2. The for loop has a built in stopping mechanism i<bytes.length. Use
> that. It is where people expect to find the stopping criteria. You
> might consider ffcounter < 5 && i < bytes.length
... unless there is a "break" statement. This is actually quite
common usage.
> 3. Fortran background people would never use x as a loop counter. It
> is reserved as a float or double temporary.
But that doesn't really affect the outcome of the program, does it?
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 12 Apr 2004 23:05 GMT
>Did I miss something? The original posting did not create the variable
>inside the for loop.
I know. It is legit C and Java, but illegitimate in other languages to
use a loop counter outside the loop. It is not the canonical form of a
loop. I think it should be avoided if possible. It is a weird thing
to do, it deserves special note by storing the loop counter is a
separate variable where you exit the loop prematurely.
You just confuse the heck out of people by writing code where loop
counters live outside the loop. You need to red flag it in some way.
His code with a comment would suffice.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 12 Apr 2004 23:07 GMT
>... unless there is a "break" statement. This is actually quite
>common usage.
The for loop's duty is to stop when an incrementing count hit a value.
Break is for other sorts of premature exit.
Break is a sort of GOTO that should be avoided if possible.
You could write the code as a while loop, but the general principle is
to use the most specific tool with the most idiomatic code.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 12 Apr 2004 23:10 GMT
>> 3. Fortran background people would never use x as a loop counter. It
>> is reserved as a float or double temporary.
>
>But that doesn't really affect the outcome of the program, does it?
No, but it makes you program more confusing since in violates a long
standing tradition that other programmers expect. i,j,k are ints.
x,y,z are floating point.
Similarly you make packages start with lower case, variable lower
case, and classes upper case. Code still works otherwise, but it makes
the code very confusing to someone used to trusting the convention.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Mark Hansen - 12 Apr 2004 23:17 GMT
>>> 3. Fortran background people would never use x as a loop counter. It
>>> is reserved as a float or double temporary.
[quoted text clipped - 4 lines]
> standing tradition that other programmers expect. i,j,k are ints.
> x,y,z are floating point.
To you perhaps. However, we're writing Java. In java, there is no
such tradition.
> Similarly you make packages start with lower case, variable lower
> case, and classes upper case. Code still works otherwise, but it makes
[quoted text clipped - 4 lines]
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Christophe Vanfleteren - 13 Apr 2004 00:09 GMT
>> No, but it makes you program more confusing since in violates a long
>> standing tradition that other programmers expect. i,j,k are ints.
>> x,y,z are floating point.
>
> To you perhaps. However, we're writing Java. In java, there is no
> such tradition.
I'm pretty sure that 99% of all loops out there are using i/j/k as a counter
variable.

Signature
Kind regards,
Christophe Vanfleteren
Hi Roedy:
Thanks for the thoughts. Really, the problem I'm having is why the
logic of the if statement doesn't work. Perhaps there is room for
improvement in the style of the code fragment, but that is not the
issue here.
Thanks
Drew
>> for (x = 0, ffcounter = 0; x < bytes.length; x++)
>> {
[quoted text clipped - 24 lines]
>3. Fortran background people would never use x as a loop counter. It
>is reserved as a float or double temporary.