This advanced control material is drawn from earlier chapters in the text.


5.4. Switch statements

Consider the following code segments. Can you effectively re-write them using a switch statement? If so demonstrate how and consider whether the switch -based version is better or worse than the if -based version version. If not, explain why not.

7.6. Recursion

Try converting the factorial function shown in the text into a similar summation function, that is computeSummation(n) returns:

1 + 2 + ... + n.

Yes, we know that this can be computed without repetition using n(n-1)/2 , but pretend that you don’t know that!