Statement:
The types of statements include declaration statements, expression statements, select statements, loop statements, jump statements, exception statements.
One: declaration statement: Into the new variable and solid. Variable declarations can optionally assign values to variables. The value must be assigned in the re-const declaration.
Cases:
int i = 0; Declare the variable i and assign a value, or you can not assign a value.
Double A;
Two: expression statement: An expression statement used to calculate a value does not store the value in a variable.
Cases:
sum = i + j; Variables I and J must be assigned before this, and sum also needs to declare the type.
int x = a + b; or perform the operation at the same time as the declaration.
Three: SELECT statement: If,else,switch,case
Four: Circular statement: Do,for,foreach,while
V: Jump statement: Break,continue,default,retrun
VI: Exception statement: try-catch-finally
Sequential statements: Execute from top to bottom
Branch statements
1.if,else statements
If is the meaning, else is the other meaning, if followed by () in parentheses to determine the condition, if the condition is met, enter the IF statement to execute the command. If the non-conformance does not enter the IF statement. else does not need to add conditions, but must be used with if, else can also be added if, but the if after the condition. If-else can be nested.
1. if (...) The conditions are judged in parentheses.
{
Execute when conditions are met;
}
2. if (...) The conditions are judged in parentheses.
{
Execute when conditions are met;
}
Else
{
Execution when conditions are not met;
}
3. if (...) The conditions are judged in parentheses.
{
Execute when condition 1 is met;
}
else if (...)
{
satisfies the condition 2 if the condition 1 is not satisfied;
}
4. if (...) Inside the brackets is the judging condition 1
{
if (...)
{
It satisfies the condition 1 and satisfies the condition 2 when executes;
}
}
else//finally does not meet the above conditions of execution here's the code
{
}
Example: 1. Do you have any money? Do you have a room? Do you have a car? Do you have the power?
Console.WriteLine ("Are You rich?" ");
String a = Console.ReadLine ();
if (A = = "no")
{
Console.WriteLine ("Do you have a room?") ");
String B = Console.ReadLine ();
if (b = = "No")
{
Console.WriteLine ("Do you have a car?" ");
String c = Console.ReadLine ();
if (c = = "No")
{
Console.WriteLine ("Do you have the ability?" ");
String d = Console.ReadLine ();
if (d = = "No")
{
Console.WriteLine ("Nothing, Roll duzi!") ");
}
else if (d = = "has")
{
Console.WriteLine ("Then you have to work hard to make money oh");
}
Else
{
Console.WriteLine ("What are you trying to say");
}
}
else if (c = = "has")
{
Console.WriteLine ("The car is also very good, in the future can go to travel");
}
Else
{
Console.WriteLine ("Can not speak well");
}
}
else if (b = = "yes")
{
Console.WriteLine ("The room is good, we have to talk about it!" ");
}
Else
{
Console.WriteLine ("What are you talking about? ");
}
}
else if (a = = "has")
{
Console.WriteLine ("Let's Get married!" ");
}
Else
{
Console.WriteLine ("Don't want to talk about rolling Duzi!" ");
}
2. The largest of the three numbers
Console.WriteLine ("Please enter the first number:");
int a = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter a second number:");
int b = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter a third number:");
int c = Convert.ToInt32 (Console.ReadLine ());
if (a >= b)
{
if (a >= c)
{
Console.WriteLine ("Number of three" +a+ "Max");
}
Else
{
Console.WriteLine ("Number of three" +c+ "Max");
}
}
Else
{
if (b >= c)
{
Console.WriteLine ("Number of three" +b+ "Max");
}
Else
{
Console.WriteLine ("Number of three" +c+ "Max");
}
}
2.switch Case Statement
Switch case must be used in conjunction with break.
Break is a jump statement. When you are in a switch case, jump out of the nearest {}
Cases:
Console.WriteLine ("Check the charges please press 1, check the balance please press 2, check the flow please press 3, business please press 4, broadband please press 5, group business Please press 7, manual service please press 0");
int a = Convert.ToInt32 (Console.ReadLine ());
Switch (a)
{
Case 1:
Console.WriteLine ("Your monthly call is 534 Yuan");
Break
Case 2:
Console.WriteLine ("Your balance is insufficient");
Break
Case 3:
Console.WriteLine ("Your remaining traffic for the month is 27M");
Break
Case 4:
Console.WriteLine ("There is no business to be done
Statement-Branch Statement