Code Spammer's Paradise

197. Error #99: Code Out Of Context

28th January 2009
For those of you not exposed to the wonderful(!) world of programming, break; commands are used in switch statements to indicate the end of each case block, ie:

switch(month) {
case 1:
text := january;
case 2:
text := feburary;
... down to...
case 12:
text := december;
case default:
text := there are only twelve months in a year you idiot;

Why do we have to use break commands instead of it being smart enough to figure out when you start another case block? So you can do this of course:

switch(month) {
case 1:
case 2:
case 3:
text := first quarter;
... etc.

Does one choice really make any sense over the other (auto-break vs manual break as most programming languages (at least the ones I know) do)? Not really in my mind.

- Luke


Your name:
Your comment:

By ComicWriterLuke at 11:20pm 28th January 2009
... and, comichub doesn't like spaces at the beginning of lines it seems, so my nice code indentation is now broken. >:(
By Leo at 7:50pm 29th January 2009
Now just put it all in one line with a nested 'if' statement. :D
By Rohan at 4:20pm 6th February 2009
It's not ComicHub, I blame HTML! Try wrapping it in pre tags, if it will let you (I don't think it will).