switch case 的这个语法是什么意思? [英] What does this syntax of switch case mean?

查看:29
本文介绍了switch case 的这个语法是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了一些这样的 C 代码:

I saw some C code like this:

int check = 10:

switch(check) {
            case 1...9: printf("It is 2 to 9");break;
            case 10: printf("It is 10");break;
} 

这个case 1...9: 是什么意思?标准吗?

What does this case 1...9: mean? Is it standard?

推荐答案

这是一个名为 case range 的 GNU C 扩展.

It's a GNU C extension called case range.

http://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html

如文档中所述,您必须在范围的低值和高值之间放置空格.

As noted in the document, you have to put spaces between the low and high value of the range.

case 1 ... 9:
    statement;

相当于:

case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
    statement;

这篇关于switch case 的这个语法是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆