Often at school, our lecturers will tell us to always include instructions Defaultat the end of the statement about the case of switching. However, I was always wondering if this is necessary for ALL (or most) scenarios?
Consider the following example in C ++:
int num = rand()%3;
switch (num)
{
case 0: methodOne();
break;
case 1: methodTwo();
break;
case 2: methodThree();
break;
}
In the case above, I feel it is impossible to have a case where it can be> 2 or <0, so do I still need to include the operator Default?
There are similar issues in SO that require Defaulta switch. The answers provided said that we should include at almost any time Default. But of all the cases that I personally encountered, it just seems redundant, as Defaultit can never be achieved.
. , , Default?
Default. error-handling, , ?