Judgment & Loop & Jump Description
This section is written in the C # language of the Control program flow statement, "control program Flow" is the control program running process meaning.
Judge
It's easy to understand: if ... Just ...
If statement: Tests whether a particular condition is satisfied, executes some code if it satisfies, and executes the code in else if it is not satisfied.
int i=0; if (i==0) { I=1;} Else { I=0;}
The program is very simple, set up an integer variable, initialized to 0, after a judgment {if the condition is satisfied: I is equal to 0, then I is assigned a value of 1, if the condition is not satisfied, that is, I is not equal to 0 o'clock, I is assigned a value of 0}.
(x==y), the two equals sign indicates whether the values on either side of the equal sign are equal, and the result is a Boolean true or false. An equals sign is an assignment, and this is where newbies often make mistakes.
Switch statement: The execution code corresponding to the value is executed by comparing a variable with multiple values and which value is equal.
I basically didn't use the switch statement because I could almost do everything that switch can do with the IF.
If you use it, be aware that each case ends with a break, and you can use default to achieve the else effect.
Loop for Loop
For (code executed before the first loop starts; The conditional statement-executes the next loop if satisfied; code executed after each loop) {loop body}
For is the most powerful loop statement, almost can use it to do all the other loop statements can do, but at some point, with the other circular statements relatively simple and convenient, and then introduce some of the time when.
While loop
while (conditional statement-executes the next loop if satisfied) {loop body}.
while (true) // Infinite Loops { if (expression)// If a condition { break is met; Jump out of the Loop }}
The break statement is a kind of jump statement, introduced in advance, to jump out of the loop, that is, to end the loop.
Do...while Cycle
do{Loop Body}while (conditional statement-executes the next loop if satisfied).
The difference between this and while is that, in any case, the contents of the loop body are executed first, and then the loop is considered.
foreach Loop
foreach (Variable type variable name in collection) {Loop body}
Sets a temporary variable that is used to access each individual in the collection, and how many objects are in the collection, looping several times.
This temporary variable can be used in the loop body to use the corresponding individual of the collection in this loop, to be able to access, to invoke its methods, to modify its properties, but not to modify temporary variables, that is, you cannot assign a value to a temporary variable.
Jump Statement Break statement
Also described earlier, used to jump out of a loop. In addition, break can also be used to exit a case statement in a switch statement.
If the break is placed outside the switch statement or loop, a compilation error is generated.
Continue statements
Used in the loop body to end this round loop and start the next loop directly. As with the break statement, it is usually used with the IF statement.
After the continue statement executes, the FOR loop is executed (code executed at the end of each loop).
Return statement
Return the method used to exit the class, returning control to the caller of the method.
If the method return type is void (which means that no return value is required), return with return is returned directly, otherwise the return statement must return a value of this type, and a null value (NULL) is allowed if the return type is a reference type.
Goto statement
Most people have never used ... Because the goto statement causes the running process to be too confusing ...
Understanding C # Series/core C #/judgment & looping & Jump