不带中断的 switch 语句的技术名称

发布于 2024-09-26 21:11:37 字数 71 浏览 4 评论 0原文

有谁知道不带中断的 switch 语句的“技术名称”?

我翻阅了几本教材,并在网上搜索了很长一段时间,没有结果。

Does anyone know the "technical name" for a switch statement without breaks?

I have looked through several textbooks and searched online for quite a while with no results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

燕归巢 2024-10-03 21:11:37

一个没有中断的 switch 语句(也没有循环,所以它不是达夫的设备),我只是调用一个跳转表

可以肯定的是,这不是结构化编程常用的工具之一。

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.

日记撕了你也走了 2024-10-03 21:11:37

当执行从一个 Case 子句继续到下一个 Case 子句时,称为“失败”。

switch (i) {
    case 1:
        // do something

    case 2:
        // do something else
        break;

    case 3:
        // do another thing
}

执行会从案例 1 到案例“失败”,但不会从案例 2 到案例 3。这就是您要问的吗?

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?

晒暮凉 2024-10-03 21:11:37

跌倒了吗?

或者您正在谈论一个没有中断的特定 switch 语句,称为 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);
    }
}

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文