Home>Article>Backend Development> How to use "switch case" statement in C language?
The usage of the "switch case" statement in the C language is to determine whether the expression after the case matches the expression after the switch. The syntax is "switch (variable expression) {case constant 1: statement; break;}".
The usage of the "switch case" statement in the C language is to determine whether the expression after the case matches the expression after the switch. Once the case If it matches, the following program code will be executed sequentially, regardless of whether the following cases match, until break is encountered.
Recommended video tutorial: "C Language Tutorial"
The syntax of the switch statement is as follows (switch, case, break and default are keywords):
switch ( 变量表达式 ) { case 常量1 :语句;break; case 常量2 :语句;break; case 常量3 :语句;break; ... case 常量n:语句;break; default :语句;break; }
When the amount expressed by the constant expression matches the constant in one of the case statements, the statements following the case statement are executed, and in sequence Continue to execute the statements in all subsequent case statements, unless a break; statement is encountered and the switch statement is jumped out. If the value of the constant expression does not match the constants of all case statements, the statements in the default statement are executed and the switch statement is jumped out.
Recommended tutorial: "C Language"
The above is the detailed content of How to use "switch case" statement in C language?. For more information, please follow other related articles on the PHP Chinese website!