Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

The judgment of C


May 11, 2021 C#


Table of contents


The judgment of C

The judgment structure requires the programmer to specify one or more conditions to evaluate or test, as well as statements to execute when the condition is true (required) and statements to execute when the condition is false (optional).

Here is a general form of judgment structure typical of most programming languages:

The judgment of C

Judgment statement

The following types of judgment statements are provided by C#. Click on the link to see the details of each statement.

Statement Describe
The if statement An if statement consists of a Boolean expression followed by one or more statements.
if... Else statement An if statement can be followed by an optional else statement, which is executed when the Boolean expression is false.
Nested if statements You can use another if or else if statement within one if or else if statement.
Switch statement A switch statement allows you to test when a variable is equal to more than one value.
Nested switch statements You can use another switch statement within one switch statement.

? : Operator

We've covered conditional operators in the previous sections. : , can be used as an alternative to if... E lse statement. Its general form is as follows:

Exp1 ? Exp2 : Exp3;

Exp1, Exp2, and Exp3 are expressions. Note the use and location of the colon.

? T he value of the expression is determined by Exp1. I f Exp1 is true, the value of Exp2 is calculated and the result is the entire ? T he value of the expression. I f Exp1 is false, the value of Exp3 is calculated, and the result is the entire ? The value of the expression.