Home > Common Problem > body text

What must be the expression after case in the switch statement?

醉折花枝作酒筹
Release: 2023-01-13 00:39:05
Original
37020 people have browsed it

The expression after the case label must be a constant expression, such as "42" or "'4'". At the same time, it must be a unique expression, that is, two cases are not allowed to have the same value.

What must be the expression after case in the switch statement?

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

The case tag (after case) must be a constant expression (constantExpression), such as 42 or '4'.

The case tag (after case) must be a unique expression; that is, two cases are not allowed to have the same value.

Other rules:

Switch can only be used for integer types in basic data types, including int, char, etc. For other types, you must use an if statement.

The parameter type of switch() cannot be real type.

What must be the expression after case in the switch statement?

Extended information:

Related extension: 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;
}
Copy after login

For more computer-related knowledge, please visit the FAQ column!

The above is the detailed content of What must be the expression after case in the switch statement?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template