I was converting a C++ algorithm to C#. I came across this for loop:
for (u = b.size(), v = b.back(); u--; v = p[v])
b[u] = v;
It gives no
The condition is u--;, because it is in the second position of the for instruction.
If the value of u--; is different from 0, it will be interpreted as true (i.e., implicitly casted to the boolean value true). If, instead, its value is 0, it will be casted to false.
This is very bad code.
Update: I discussed the writing of "for" loops in this blog post. Its recommendations can be summarized in the following paragraphs:
A for loop is a practical, readable (once you get used to it) and terse construct, but you need to use it well. Because of its uncommon syntax, using it in a too imaginative way is not a good idea.
All parts of the for loop should be short and readable. Variable names should be chosen to make it easy to understand.
This example clearly violates these recomendations.