the types of statements include : Declaration statements, expression statements, select statements, loop statements, jump statements, exception statements
1. Declare statement citation: Enter a new variable or constant. Variable declarations can optionally assign values to variables. A value must be assigned in a constant declaration.
For example:
int i = 0;//declares the variable i and assigns a value, or it can not be assigned.
Double D;
"//" means a line of comments, "/*...*/" can comment on a section of the area, the content of the comment becomes green.
2. Expression statement: An expression statement used to evaluate a value must store the value in a variable.
For example:
sum = i + j;//variables I and J must first 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.
3. SELECT statement: If, else, switch, case
4. Looping statements: Do, for, foreach, while
5. Jump statement: Break, continue, default, return
6. Exception statement: try-catch-finally
First, branch ( select ) statement:
if (judging condition) {program code, operation, etc.}, if () {} else{}, if () {} else if () {}......else{}, if () {if () {}} else{}
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.
//Classification of statements//sequential statements, branching (selection) statements, looping statements//Branch (selection) statement//format 1 if () {}//int a = 6; //if (a <= && a >= 0); //{ //Console.WriteLine ("The number you have entered is less than 100.") "); //} //Console.WriteLine (a); //Console.ReadLine (); //Format 2 if () {}else{} two Select one//if satisfied, walk If,else won't go//if the if is not met, else will be sure to go//Console.Write ("Please enter an integer:"); //int a = Int. Parse (Console.ReadLine ()); //if (a > Ten)//{ //Console.WriteLine ("You have entered a number greater than 10.") "); //} //Else//{ //Console.WriteLine ("You are not entering a number greater than 10.") "); //} //Console.ReadLine (); //Format 3 if () {} else if () {}...else{} multiple Select one//as long as there is an if or else if satisfies the condition, executes the//everything from below it does not need to be judged read//Console.Write ("Please enter a month:"); //int month = Int. Parse (Console.ReadLine ()); //if (Month > 2 && month < 6)//{ //Console.WriteLine ("You entered the month of Spring!") "); //} //else if (Month > 5 && month > 9)//{ //Console.WriteLine ("You entered the month of the summer!") "); //} //else if (Month > 8 && month <)//{ //Console.WriteLine ("You entered the month of Autumn!") "); //} //else if (month = = | | month = = 1 | | month = = 2)//{ //Console.WriteLine ("You entered the month of winter!") "); //} //Else//{ //Console.WriteLine ("Your input is wrong!") "); //} //Console.ReadLine (); //Format 4 If nesting//first of all, set a large range, and then go in to judge a variety of small situationsConsole.Write ("Please enter a month:"); intmonth =int. Parse (Console.ReadLine ()); if(Month >=1&& Month <= A) { if(Month >2&& Month <6) {Console.WriteLine ("you entered the month of spring! "); } Else if(Month >5&& month >9) {Console.WriteLine ("you entered the month of the summer! "); } Else if(Month >8&& Month < A) {Console.WriteLine ("you entered the month of autumn! "); } Else //month = = | | month = = 1 | | month = = 2{Console.WriteLine ("you entered the month of winter! "); } } Else{Console.WriteLine ("your input is wrong! "); } console.readline ();
Second, switch case format multiple select one
//Switch Case multiple Select oneConsole.WriteLine ("1. Hamburgers"); Console.WriteLine ("2. Chicken Leg"); Console.WriteLine ("3. Chicken Rice Flower"); Console.WriteLine ("4. Chicken Roll"); Console.Write ("Please enter the product number of your choice:"); stringA = Console.ReadLine ();//It can also be of type int: int a=int. Pars (Console.ReadLine ()); //Switch Format Switch(a)//the variable name is inside the parentheses { Case "1"://The case must be followed by a space, and the int type would be the following: Box 1Console.WriteLine ("the product you selected is: Hamburger! "); Break;//the function is to jump out of the nearest curly brace Case "2": Console.WriteLine ("your choice of product is: Chicken leg! "); Break; Case "3": Console.WriteLine ("your choice of product is: Chicken rice flower! "); Break; Case "4": Console.WriteLine ("the product you selected is: Chicken roll! "); Break; default://equivalent to else, the above may not beConsole.WriteLine ("your input is wrong! This item does not exist! "); Break; } console.readline (); //if Format//if (A = = "1")//{ //Console.WriteLine ("The Product you selected is: Hamburger! "); //} //else if (a = = "2")//{ //Console.WriteLine ("The Product you selected is: Chicken leg!") "); //} //else if (a = = "3")//{ //Console.WriteLine ("The Product you selected is: Chicken rice flower!") "); //} //else if (a = = "4")//{ //Console.WriteLine ("The Product you selected is: Chicken roll! "); //} //Else//{ //Console.WriteLine ("Your input is wrong!") This item does not exist! "); //} //console.readline ();
Statement: Spoke statement, switch case--7 month 22nd