"PHP Syntax Structure Classification"
Cyclic structure, sequential structure and selection structure
One, circular statement
(1), Foreach Loop
Defined:
A foreach loop is used to iterate through all the items in a collection, the most typical set type is an array, and in a foreach loop, one or more commands are run against each item in the array
Syntax structure:
"Example, you need to loop through the values in the $string array."
$string = "Apple", "banana", "orange"
Foreach ($fruit in $string)
{
Write-host $fruit
}
"Example, to loop through the result set returned by the Get-childitem command"
Foreach ($file in Get-childitem c:\)
{
Write-host $file
}
(2), for loop
Defined:
A For loop is used to create a command that runs in a command block when a specified condition evaluates to True, and the typical use of a For loop is an array of values that are iterating through
Syntax structure:
"Example, looping through the number 1 to 10."
for ($i =1; $i-le; $i + +)
{Write-host $i}