How to write two formats of case statement

Do case statements in C have to be followed by single quotes?

A case statement does not have to be followed by single quotes; single quotes are required only if the case is followed by a character.

case is used with the switch statement in the following format:

switch(expression)

{

case constant expression 1:statement 1;break;

case constant expression 2:statement 2;break;

……

case constant expression n:statement n;break;

default:statement n+1;

}

Examples are as follows:

Using single quotes case:

char ch=’S’;

int i=0;

switch(ch) // ch is a character type, so use single quotes

{

case ‘A’ : i++; break;

case ‘S’ : i+=2; break;

default : i–;

}

Without single quotes case:

int ch=5;

int i=0;

switch(ch) // ch is of type int, so no single quotes are used

{

case 3 : i++; break;

case 5 : i+=2; break;

default : i- -;

}

Case statement writing in ASP

If you write it in selectcase, it could look like this:

selectcasetj

case1

response.write “1.gif”

case2

response. write “2.gif”

‘… And so on

endselect

In fact, if the filename is a one-to-one relationship with tj, you can just write it like this:

response.write(tj&”.gif”)

How to write a switchcase statement in c

An example of a switchcase statement in c is:

#include

intmain(void){

inta;

printf(“inputintegernumber:”) ;

scanf(“%d”,&a);

switch(a){

case1:printf(“Monday\n”);break;

case2:printf(“Tuesday\n”);break;

case3:printf(“Wednesday\n”);break;

case4:printf(“Thursday\n”);break;

case5:printf(“Friday\n”);break;

case6. printf(“Saturday\n”);break;

case7:printf(“Sunday\n”);break;

default:printf(“error\n”);

return0;

}<

Program Interpretation:

This program is asking for a number to be entered and outputting the English word for the week it corresponds to.

Note items:

1. The value of each constant expression after case cannot be the same, otherwise an error will occur.

2. After case, more than one statement is allowed, which can be enclosed without {}.

3, the case and default clauses can change the order of precedence, without affecting the program execution results.

4. The default clause can be omitted.

c language switch statement format

Switch is another selection structure statement used in place of a simple ifelse statement with multiple branches, with the following basic format:

switch(expression){

case integer value 1:statement 1;

case integer value 2:statement 2;

……

case integer n:statement n;

default:statement n+1;

}

It is executed as follows:

1) First, it calculates the value of the “expression”, which is assumed to be m.

2) It compares the values of the “expressions”, starting with the first one. case, compare “integer value 1” and m, if they are equal, then execute all the statements after the colon, that is, from “statement 1” to “statement n+1 “, regardless of whether the following cases match.

3)If “integer value 1” and m are not equal, skip “statement 1” after the colon and continue comparing the second case, the third case…. …once found and an integer value is equal, it will execute all the statements after. Assuming that m is equal to “integer value 5”, then it will be executed from “statement 5” all the way to “statement n+1”.

4) If no equal value is found until the last “integer n”, then “statement n+1” is executed after default.