The Daily WTF
Most (but clearly, not all) programmers have generally mastered the basic for loop. If you really want to separate the wheat from the chaff, ask them to write a for loop that counts by two, or three, or some other arbitrary number.
That’s what happened at J Banana‘s workplace, where they needed to parse in tokens from a config file. They come in key value pairs, so the code needs to count by twos. This was their solution:
for(int i=0; i<values.size(); i= i++) { map.put(values.get(i), values.get(++i)); i++; }
At a quick glance, you may end up scratching your head: the ++ operator appears three times, but they want to count by twos, and yet this code works. It works, in part, because of the developer’s incompetence.
In the body of the loop, values.get(i) gets the current item in the list, and values.get(++i) does a pre-increment on i, getting the
To read the full article click on the 'post' link at the top.