Well Horstl has a cool way of doing it.
This is the old way Id do it.
while ($somefunction) && (%a < %b) {
set %variable $addtok(%variable,output text,32)
inc %a
}
msg #channel %variable
btw, if ya really want help try and use actual code instead of "$somefunction" or "output text".
Makes it easier for scripters to see what you need.