Operator and spoke statement: If, else If,else;switch case

Source: Internet
Author: User
Tags switch case

Branch statements:

if else if else; switch case

--How to use if else if else:

Console.WriteLine ("Please Punch");--Output "please punch"
int a = Convert.ToInt32 (Console.ReadLine ());--Define a variable a
Random i = new random ();--Random number
int x = I.next (3);--variable x can be randomly given a number of 0-3
if ((a-x = = 1) | | (A-x = =-2))
{
Console.WriteLine ("PC =" + x);
Console.WriteLine ("Man wins");
}
else if (x==a)
{
Console.WriteLine ("PC =" + x);
Console.WriteLine ("Draw");
}
Else
{
Console.WriteLine ("PC =" + x);
Console.WriteLine ("Man loses");
}

--How to use the switch case:

int a = Convert.ToInt32 (Console.ReadLine ());--Define a variable a
Switch (a)--Remember to put only one variable in the switch bracket
{
Case 1:
Console.WriteLine ("Monday");
Break--Add a break at the end of each case, or the statement error will be displayed
Case 2:
Console.WriteLine ("Tuesday");
Break
Case 3:
Console.WriteLine ("Wednesday");
Break
Case 4:
Console.WriteLine ("Thursday");
Break
Case 5:
Console.WriteLine ("Friday");
Break
Case 6:
Console.WriteLine ("Saturday");
Break
Case 7:
Console.WriteLine ("Sunday");
Break
Default
Console.WriteLine ("You may have entered incorrectly");
Break

}

Operator:

Math operators: +-*/%

Compare Operational Services:> < >= <=! = = =

Logical operator:&& (and) | | (OR)! (Inverse effect)

Assignment service: = + = = *=/=%=

Conditional Operational Service: (comparison expression)? (Statement I): (statement II)

Operator and spoke statement: If, else If,else;switch case

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.