Learning Process Control must first understand the flowchart, flowchart is to use some standardized graphics, to visualize a function of the implementation steps, you can make some more complex logic operations become intuitive, easy to understand.
A Process Control statement is an important knowledge in C #, with an If statement that represents a decision, a switch statement that represents the selection, a while statement that represents a loop, a do-while statement, a for statement, and a break statement that represents the end, a continue statement.
Now to say the function of the above statement, if judgment: if the condition 1 is established, then execute Code 1, otherwise determine whether the condition 2 is set up, if it is executed code 2, if none of the above, then execute code n;switch Select: First calculate the value of the variable or expression, Compare the value from top to bottom, and then the value following the case, and when you encounter the same, run the code below it, and then run the code after default, note: Break must be written. The value following the case is a constant, which is compared to the variable or expression following the switch. The double type cannot use this selection statement. While: If the loop condition is true, then the loop body is executed, after execution, then the condition is true, if true, then execution, until the condition is false, only stop; Do while: Perform a loop body first, then determine whether the condition is satisfied, if satisfied, then execute again, and then determine whether the condition is satisfied, Until the condition is not satisfied to end the loop; for: Run expression 1, determine if the loop condition is true, if true, execute the loop body, run the expression 2 after execution, and then judge the loop condition ... The loop will end until the loop condition is false. Finally, the concluding sentence, break: Immediately end the current loop, into the next cycle;
These statements use variables, but also pay attention to the scope of the variable, it means: A variable in the definition of the curly brace, the variable is valid, otherwise invalid. Note: When defining a variable in a location, the variable name must not be the same as the variable name where the scope overrides the location.
Process Control in C #