The foreach command iterates over a set of fields - not events. So if I had 6 fields with names that all started with Percent, I could use the foreach command to do the same set of actions for each field Percent*.
You don't specify iteration in Splunk like in programming languages. In fact, you generally don't specify iteration at all.
I suspect that what you want is quite different. You have a set of events and you want to calculate a few field for the various subsets of events. Try something like this: