For Each key value...Next
Command Description
Sequentially obtain (also known as traverse) each element in an array or dictionary, and execute the following block of statements separately for the index and value of each retrieved element. For an array, the index is the position of the element (starting from 0); for a dictionary, the index is the name of the element.
Command Prototype
For Each key, value In dataStruct
Next
Parameter Description
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
key | True | id | key | Traversal Key |
value | True | id | value | Traverse value |
dataStruct | True | expression | dictVar | The data structure to be traversed |
Demo
TracePrint("------------------------------------ Traverse the dictionary--------- ----------------------------------")
//-------------------------------------------------------------------------------
//[Remarks] Loop through each piece of data in Collection , substitute the name of the data (when corresponding to a dictionary) or index (when corresponding to an array) into key, substitute the value of the data into value and execute the Block statement block .
TracePrint("Let the dictionary be a = {'a':'U','b':'i','c':'B','d':'o','e':'T' }, traverse and print each key, value")
a = {'a':'U','b':'i','c':'B','d':'o','e':'T'}
For Each key,value In a
TracePrint "key value: "&key&" value value: "&value
Next