Does anyone know the "technical name" for a switch statement without breaks?
I have looked through several textbooks and searched online for quite a whi开发者_JAVA百科le with no results.
A switch statement with no breaks (and no loop, so it's not Duff's Device), I would just call a jump table.
Not one of the tools commonly used for structured programming, that's for sure.
When execution continues from one Case clause to the next it's called "fall-through".
switch (i) {
case 1:
// do something
case 2:
// do something else
break;
case 3:
// do another thing
}
Execution will "fall through" from case 1 to case, but not from case 2 to case 3. Is this what you're asking?
Fall through?
Or are you talking about a specific switch statement with no breaks, called Duff's Device?
send(to, from, count)
register short *to, *from;
register count;
{
register n=(count+7)/8;
switch(count%8){
case 0: do{ *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
}while(--n>0);
}
}
精彩评论