The format of the for loop described earlier is as follows:
For VARNAME in List;do
Statement
...
Done
The For loop in this format is the statement that assigns each value in the list to the variable varname, and then executes in the loop body. When no value in this list is copied to the variable varname, the loop ends.
Here we are introducing a for loop similar to the C language
The syntax format is as follows:
For ((expre1;expre2;expre3));d O//note the FOR keyword and parentheses have spaces
Statement
...
Done
There are 3 expressions in the parentheses, with ";" for each expression. Separated
Where Expre1 is generally used for initialization variables, you can omit
The Expre2 is a control condition, that is, the loop body is executed if the condition is met, and the loop body is exited.
Expre3 is used to modify the value of a variable, or it can be omitted.
This for loop works by first judging if the variables in the expre1 conform to Expre2, executing the statements in the loop body, or exiting if they are not. If the expre3 is executed, the value of the variable is changed, and then when the value of the change is determined to conform to Expre2, then the statement in the loop body is executed, and then the loop is exited, and so on, to complete the entire looping process.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/40/E5/wKiom1PPlGni1kC8AAIreKU9WG8347.jpg "title=" 3.png " alt= "Wkiom1pplgni1kc8aaireku9wg8347.jpg"/>
Where num is Expre1, can be omitted, can also be declared outside the loop body
Num<=105 is a expre2, which determines the number of cycles for which the condition is controlled.
num++ is expre3, used to modify the value of a variable
Until cycle of control structures
Before we talked about the while loop, it was when expression was formed, the statement in the loop body was executed, and the statement in the loop body was exited when it was not. And our until is just the opposite, when expression is set up, the statement in the loop body executes, and expression exits the loop when it is formed.
The syntax format is:
Until Expression;do
Statement
...
Done
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/40/E6/wKiom1PPlgrC1rsHAANu8gntYmQ762.jpg "title=" 1.png " alt= "Wkiom1pplgrc1rshaanu8gntymq762.jpg"/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/40/E6/wKiom1PPliaxJ8ikAAF4jrJilgU236.jpg "title=" 11.png "alt=" Wkiom1ppliaxj8ikaaf4jrjilgu236.jpg "/>
This article from the "Linux Learning Path" blog, declined reprint!
Another use and until loop for the for loop of the Linux learning path