For Each... In loop structure
The memory address of the image is extracted from the memory and received by the variable following For Each.
In the Next statement, the Next project in the set object is taken out, and the memory address is
For Each is followed by a variable until all objects in the set object are retrieved.
Outbound
<% @ Page Language = "VB" %>
<Script runat = "server">
Sub Page_Load (Sender as object, e as eventargs)
Dim strDay as string
Dim arrWeekDays () as String = {"Monday", "Tuesday ",
_
"Wednesday", "Thursday", "Friday "}
For Each strDay in arrWeekDays
Response. Write (strDay & "<br> ")
Exit
Next
End sub
</Script>
<Html> <body>
</Body>
This statement starts with the for keyword, followed by parentheses. Inside the brackets is an initiator.
In a condition and an iteration statement, they are all separated by semicolons. Nested statement in
Parentheses.
The following is an application example of the for statement:
For (int I = 0; I <= 6; I ++)
{
Response. Write ("The current value of loop variable I is:" + I. ToString
(). Trim () + "<br>");
}
② Foreach statement
This statement is used to loop through elements in a set. Array support in C #
Therefore, you can use the foreach statement to process every element in the array.
.
When using a foreach statement, first enter the foreach keyword and then parentheses.
The brackets must contain the following information: the type of elements in the set and the identifier of the elements in the set.
The name, keyword in, and set identifier. Nested statements are enclosed in parentheses.
The following is an application example of the foreach statement:
Int [] intArray;
IntArray = newint [6];
IntArray [0] = 0;
IntArray [1] = 1;
IntArray [2] = 2;
IntArray [3] = 3;
IntArray [4] = 4;
IntArray [5] = 5;
Foreach (int ArrayElement in intArray)
{
Response. Write ("The current value of the array variable ArrayElement is:
"+ ArrayElement. ToString (). Trim () +" <br> ");
}