Latest web development tutorials

C ++ judgment

Analyzing structure requires the programmer to specify one or more conditions to be evaluated or tested, as well as statements statements (required) and the condition is false to execute (optional) condition is true when you want to perform.

The following is the general form in most programming languages ​​typically determine the structure:

C ++ The judge sentences

Judge sentences

C ++ programming language provides the following types of judgment statement. Click on the link to view the details of each statement.

语句描述
if 语句 一个if 语句由一个布尔表达式后跟一个或多个语句组成。
if...else 语句 一个if 语句后可跟一个可选的else 语句,else 语句在布尔表达式为假时执行。
嵌套 if 语句 您可以在一个ifelse if语句内使用另一个ifelse if语句。
switch 语句 一个switch语句允许测试一个变量等于多个值时的情况。
嵌套 switch 语句 您可以在一个switch语句内使用另一个switch 语句。

?: Operator

We have already explained in previous chapters of the conditional operator:? , Can be used insteadif ... elsestatement. Its general form is as follows:

Exp1 ? Exp2 : Exp3;

Wherein, Exp1, Exp2 and Exp3 expression. Please note that the use of the colon and location.

? Exp1 value of the expression is determined. If Exp1 is true, then the calculated value Exp2, the result is the entire? Expression. If Exp1 is false, then the calculated value Exp3, the result is the entire? Expression.