1. While loop
Code format:
while (loop condition) { // loop Body }
Flow chart:
Interpretation:
If the loop condition is true, the loop body is executed
After executing the loop body, determine if the condition is true
If true, then the loop body is executed
And then judge whether the condition is true, so it goes on, until the result of the loop condition is false, it will end the loop
Case:
Use the dead loop to get the correct information for user input
define variables; while(true) {Console.Write ("Prompt for user input:"); Variables=get user input; if(variable satisfies the requirement) { Break;//end the endless cycle } Else{Console.Write ("error message, press ENTER to continue"); Console.ReadLine (); Console.clear (); }}//after the loop is over, the correct data must be saved in the variable
2.do while loop
Code format:
Do { // loop body }while (loop condition)
Flow chart:
Interpretation:
Perform a loop body first
It then determines if the loop condition is satisfied and executes the loop body again if satisfied
And then determine whether the condition is satisfied, until the condition is not satisfied, to end the loop
3.for Cycle
Code format:
for (expression 1; loop condition; expression 2) { // loop Body }
Flow chart:
Interpretation:
Run an expression 1
To determine if the loop condition is true, if true, then execute the loop body, run the expression 2 after execution, and then judge the loop condition ...
The loop will not end until the loop condition is false
4.foreach Cycle
Code format:
foreach inch array or collection) {// loop Body }
Interpretation:
Interpretation:
From an array or collection, remove the data for each item in turn
Assigns the data to the loop variable every data is fetched
Run the loop body once each time you assign a value
Loop Statement Summary (code in C # for example)