If judgment
Writing format:
if (condition 1)
{
Code 1
}
else if (condition 2)
{
Code 2
}
Else
{
Code n
}
Note: If condition 1 is established, then execute Code 1, otherwise determine whether the condition 2 is established, if set up, then execute code 2; Execute code n if none of the above conditions are true
Where else if can repeat any number of times
Condition 1, Condition 2 are of type bool
Code 1, code 2, code n any number, any function
If code 2 has only one line of code, the big empty number can be omitted
Switch selection
Code format:
switch (variable or expression)
{
Case value 1
Code 1
Break
Case Value 2
Code 2
Break
Default
Code n
Break
}
Note: The value of a variable or expression is computed first, and the value from top to bottom is compared to the value following the case, and if the same value follows a case, the code below the case is run, and if it is not the same as all values, the code after the default is run
A value of 1, a value of 2 must be a specific value, and can be compared with a variable or an expression
Only String, char, BOOL, enumeration, integer comparisons are supported
Integers: Byte, short, ushort, int, uint, long, ulong
Where the case value can be multiple
Default can only be O or one
Can be turned into if, but if it does not necessarily turn into switch
While loop
Writing format:
while (loop condition)
{
Loop body
}
If the loop condition is true, then the loop body is executed, after the loop body is executed, the condition is judged to be true, if true, then the loop body is executed, and then the condition is true, so it goes on until the loop condition is judged to be false, to end the loop.
Loop condition: value, variable, expression
Loop body: Any function, any number of code
Must be of type bool
Do and loop
Writing format:
Do
{
Loop body
}
while (cyclic condition);
Executes the loop body first, then determines whether the loop condition is satisfied, executes the loop body again if satisfied, and then determines whether the condition is satisfied until the condition is not satisfied before ending the loop
For loop
Writing format:
for (expression 1; loop condition; expression 2)
{
Loop body
}
Run expression: Determine whether the loop condition is true, if true, then execute the loop body, run the expression after execution 2, then judge the condition ... until the loop condition is false to end the loop
Break and Continue
Break
Switch immediately ends the switch selection
Loop End Loop immediately
Continue
End immediately when the cycle enters the next cycle
Recognize several looping commands in the C # language