Originally Posted By: FroggieDaFrog
I'd also Like to see a foreach loop:


foreach (string,delimiter) { }
Code:
foreach (this is a string,32) {
  echo -a $fedata
}
would echo:
this
is
a
string


foreach -h (hashtable,<condition>)[.data] { }
Code:
 foreach -h (table,*match item*) {
  echo -a $feitem $fedata
}
echo each matching item, and it's data.
the .data property would have the loop match data


foreach -i (inifile,[topic],<condition>) { }
Code:
foreach -i (inifile,sometopic,*).data {
  echo -a $fetopic $feitem $fedata
}
matches items in an ini file.
the .data property will have the loop match data



i like the general idea, but implementation in the nature that you described seems complicated and messy. the notion of a control structure such as the proposed foreach() having these accompanying switches and identifiers is quite bizarre, albeit a novel one :P the task of iterating is not made any simpler since, it seems, a user would be required to understand and be familiar with the behaviour of $gettok, $hfind and $ini to be able to effectively use those that you mentioned. the end result of one of these loops would resemble currently scriptable methods in complexity and size, so it doesn't appear to provide enough added benefit to the scripting language.

i had a similar thought a couple of weeks ago while we were discussing a hypothetical foreach() on EFnet's #mIRC. suggestions were being thrown around and my thoughts gradually converged upon an idea that, at the time, i believed to be epiphanic. what if we could abstract the idea away from association with any particular command or identifier and create a general purpose foreach () that would iterate through a collection of items exactly as $submenu() does (send 1 to the alias/identifier and keep increasing until it returns $null). an example might be:

Code:
foreach ($gettok(%var, $1, 32)) {
  ; $v1 is filled with the return value
}


but quick as the idea came to me, so too was it dismissed as i realized the obvious folly: that it is, for all intents and purposes, equivalent to:

Code:
var %i = 1
while ($gettok(%var, %i, 32) != $null) {
  ; $v1 is filled with the return value
  inc %i
}


i had mentally tweaked and adapted the idea to the point where it resembled, almost entirely, something that is readily available to me already ;D great story right


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde