C # Tutorial C # Judging

Source: Internet
Author: User
Tags nested switch
C # judgment

Judging the structure requires the programmer to specify one or more conditions to evaluate or test, and the statement to execute when the condition is true (required) and the statement to be executed when the condition is false (optional).

The following is the general form of a typical judgment structure in most programming languages:

Judgment statement

C # provides the following types of judgment statements. Click the link to see the details of each statement.

Statement

Describe

An If statement consists of a Boolean expression followed by one or more statements.

The If...else statement can be followed by an optional else statement after an if statement, and the Else statement 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 a situation where a variable equals multiple values.

Nested switch statements You can use another switch statement within a switch statement.


? : operator

We have explained the conditional operators in the previous chapters. : Can be used instead of if...else statements. Its general form is as follows:

Exp1? EXP2:EXP3;

Among them, EXP1, EXP2, and Exp3 are expressions. Notice the use and position of the colon.

? The value of an expression is determined by EXP1. If EXP1 is true, the value of EXP2 is computed and the result is the whole? The value of an expression. If EXP1 is false, the value of EXP3 is computed and the result is the whole? The value of an expression.

The above is the "C # tutorial" C # Judgment of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.