C语言中的select语句是一种条件判断语句,用于根据不同的条件执行不同的操作。它的基本使用方法如下:
1.基本语法
```
select(expression){
case constant-expression:
statement(s);
break;
case constant-expression:
statement(s);
break;
default:
statement(s);
}
```
2.使用case语句
```
int a = 2;
switch(a){
case 1:
printf("a=1");
break;
case 2:
printf("a=2");
break;
default:
printf("a is not 1 or 2");
}
```
3.使用default语句
```
int a = 3;
switch(a){
case 1:
printf("a=1");
break;
case 2:
printf("a=2");
break;
default:
printf("a is not 1 or 2");
}
```
4.使用多个case语句
```
int a = 3;
switch(a){
case 1:
case 2:
printf("a is 1 or 2");
break;
default:
printf("a is not 1 or 2");
}
```
5.使用break语句
```
int a = 2;
switch(a){
case 1:
printf("a=1");
break;
case 2:
printf("a=2");
break;
default:
printf("a is not 1 or 2");
}
```
6.使用嵌套switch语句
```
int a = 1;
int b = 2;
switch(a){
case 1:
switch(b){
case 1:
printf("a=1, b=1");
break;
case 2:
printf("a=1, b=2");
break;
}
break;
case 2:
printf("a=2");
break;
default:
printf("a is not 1 or 2");
}
```