Often when I'm writing a small script to do a specific thing, I need a simple counter to perform an action a given number of times. For example, if I want to echo the sum of all numbers from 1 to 10, I have to do:

Code:
/alias sum { var %sum,%n = $2 | while (%n) { inc %sum %n | dec %n } | return %sum }
//echo -a $sum(1,10)


It would be much nicer and easier to have an identifier, such as $for, that would let me just do:

Code:
//echo -a $for(%x,1,10,1,inc %sum %x) %sum


The reason for having this as an identifier is so that iterative tests can be done in a single command, such as:

Code:
$for(%x,1,$nick($active,0),2,if ($nick($active,%x) == Danny) return Danny is odd!)


would return "Danny is odd!" if Danny were in an odd-numbered position in the active window's nicklist.

The basic form I envision for such an identifier is similar to how for loops in C are often used.

Code:
$for(<variable>,<start>,<end>,<step>,<code>)


I managed to write an alias to provide this functionality, but it suffers from the fact that raw code cannot be passed in without formatting it correctly (either using $+ or $eval(<code>,0)). It also is worthless when trying to write small scripts for others, as in done in many help channels throughout the IRC community. Instead of using a clean for loop, we are stuck using external aliases, resorting to more complex while loops, abusing $regsubex, and running $findfile on large directories. My alias is as follows, and I hope it can be converted to a real built-in identifier.

Code:
alias for {
  set -l [ $1 ] [ $2 ]
  while ($eval($1,2) <= $3) {
    $eval($5,2)
    inc $eval($1,1) $4
  } 
}

This alias must be called by wrapping the parameters:
Code:
//echo -a $for($eval(%x,0),1,10,1,$eval(inc %sum %x ,0)) %sum