Nobody of my audience could solve the Piccolo Quiz - Bad Code I. This is awful. I have to drown my grief in the unwon piccoloechen now. I've been so proud of you, my dear audience, but now ... bottomless disappointment. Folks, it was so easy. But before solving the problem, we turn to the new task, which demands skills in other fields. Question: In what famous contribution to the set of great movies does the little chap below appear? The first who gives the right answer wins, guess what, a Rotkaeppchen Piccolo. This time answers to the comments please.
Now for solving the previous task: if(number+iterations == limit) was the problem. The function implies that number is smaller then limit when the parameters are passed but never checks if this is the case. So, calling doSomethingUpTo(0, 0) would make the function run infinitely, which is bad indeed. To solve the problem one should consider changing the if-statement to something like if(number+iterations < limit) with iterations = -1 as start value or, if passing number > limit is actually an error, throwing an exception.
Commenting is closed for this article.