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