Enze Third Day (select Structure "If...else" in C #)

Source: Internet
Author: User

Hello, it's time for me to sum up my classroom knowledge. What you learned today in the cloud and college is the IF statement under Select Structure in C #. Here's a summary of what you've learned today.

theory : The IF statement is the most common choice structure statement. It is determined whether to execute the following block of statements, depending on whether the given condition (often consisting of a relational expression and a logical expression) is true. The IF statement has three types of structure:

Real :1. an IF structure of a select path

  if (condition) {    statement block;}       // If the condition is true, the following statement block is executed, or if the condition is false, the IF statement ends. If the statement has only one line of code, the braces on the outer layer of the structure can be omitted. 

For example:

Namespace Practice 005_ user Input {    class program    {        static void Main (string[] args)        {             if (5>10)             Console.WriteLine ("5:10 Large");}}}    

2. The IF structure of two selected structures

For example : The user enters a year, and if it is run year, the output is true, and if not, the output is false.

3. If structure for multiple selection paths

if (condition)

{

Statement Block 1;

}

else if (condition 2)

{

Statement Block 2;

}

.

.

.

Else

{

statement block N;

}

In this structure, when the value of condition 1 is true, the statement block 1 is executed, and then the IF statement ends; otherwise, if the value of condition 2 is true, the statement block 2 is executed, and so on. If all conditions are not true, then the last else statement block N is executed.

For example: test results evaluation

          Console.WriteLine ("Please enter your score");
int score = Convert.ToInt32 (Console. ReadLine ());
if (score >=90)
{
Console.WriteLine ("The student's performance is assessed as: A");
Console.readkey ();
}
else if (score >=80 && score <90)
{
Console.WriteLine ("The student's performance is assessed as: B");
Console.readkey ();
}
else if (score >=70 && score <80)
{
Console.WriteLine ("The student's assessment result is: C");
Console.readkey ();
}
else if (score >= && score < 70)
{
Console.WriteLine ("The student's assessment result is: D");
Console.readkey ();
}
Else
{
Console.WriteLine ("The student's assessment results are: E");
}
Console.readkey ();

Well, today summed up here, looking forward to tomorrow's meet again. Come on, enze!.

Enze Third Day (select Structure "If...else" in C #)

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.