I'd like to know how to use the Foreach construct in ASH. I have a map declared at the beginning of one of my scripts:
that I add items to during the course of the script:
at various points in my script I could have any number of items in this map, and I'm looking to create a function I can call to set all the items in the map to a specific value using something similar to the following:
Can someone please explain the syntax I would use? Does a variable go where key would be and then I plug in the variable into the subsequent statement? Are the empty brackets required when referencing the map in the foreach statement?
Code:
string [string] CarColor;
Code:
CarColor["Toyota"]="red";
CarColor["Ford"]="white";
CarColor["MBW"]="black";
at various points in my script I could have any number of items in this map, and I'm looking to create a function I can call to set all the items in the map to a specific value using something similar to the following:
Code:
void SetAllToBlue()
{ for each key in CarColor[] { CarColor[key] = "blue"; } }
Can someone please explain the syntax I would use? Does a variable go where key would be and then I plug in the variable into the subsequent statement? Are the empty brackets required when referencing the map in the foreach statement?