Basic application of If statement in C #

Source: Internet
Author: User

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

If the Boolean expression is true, the code block within the IF statement is executed. If the Boolean expression is false, the first set of code after the end of the IF statement (after closing the parentheses) is executed.

               int a = ten;            /* Check the Boolean condition using the IF statement *            /if (a <)            {/                * If the condition is true, output the following statement *                /Console.WriteLine ("A is less than");            }            Console.WriteLine (The value of "a" is {0} ", a);            Console.ReadLine ();

  

If...else if...else Statements

An if statement can be followed by an optional else If...else statement, which can be used to perform a variety of conditions.

When using the If...else if...else statement, the following points need to be noted:

    • An if can be followed by 0 or an else, it must be after any other else if.
    • An if can be followed by 0 or more else if, they must precede else.
    • Once an else if match succeeds, the other else if or else will not be executed
if (Boolean_expression 1) {/   * When Boolean expression 1 is true, execute */}else if (boolean_expression 2) {/   * When Boolean expression 2 is True */}else if (Boole An_expression 3) {/   * When Boolean expression 3 is True */}else {/   * is executed when none of the above conditions are true */}

Here's an example:

   /* local variable definition */            int a = +;            /* Check the Boolean condition *            /if (a = =)            {/                * If the IF condition is true, then output the following statement *                /Console.WriteLine ("A's value is ten");            }            else if (a = =)            {/                * If the else if condition is true, output the following statement *                /Console.WriteLine ("A's value is");            }            else if (a = =)            {/                * If the else if condition is true, output the following statement *                /Console.WriteLine ("A has a value of");            }            else            {                /* If none of the above conditions are true, output the following statement *                /Console.WriteLine ("No matching value");            }            Console.WriteLine (The exact value of "a" is {0} ", a);            Console.ReadLine ();

  

Basic application of If statement in C #

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.