a few minutes ago I was attempting to explain to someone how to use nested while loops, and after trying to paste a one-liner and not getting the expected output, I put it into an alias spaced out properly, and it worked.
from the code below, /suh doesn't work as expected, but /suh2 does.
alias suh { var %i = 1 | while (%i <= 5) { var %x = 1 | while (%x <= 5) { echo -a %i %x | inc %x } | inc %i } }
alias suh2 {
var %i = 1
while (%i <= 5) {
var %x = 1
while (%x <= 5) {
echo -a %i %x
inc %x
}
inc %i
}
}
I thought this bug was fixed years ago.
whiletest { var -s %i = 1 | WHILE (%i < 5) { var -s %j = 1 | WHILE (%j < 5) { noop | inc -s %j } | inc -s %i } }
Outputs:
* Set %i to 1
* Set %j to 1
* Inc %j to 2
* Inc %j to 3
* Inc %j to 4
* Inc %j to 5
* Inc %i to 2
The inner-while will loop fine, but the outer-while just ends without looping once.
It looks like this issue dropped off my radar a long time ago. I have been looking through the script parser over the last week or so to see if I can find a way solve this and other while loop issues. The while loop parser looks like really old, temperamental code. I have implemented a solution that passes a hundred or so while loop test cases (random, convoluted combinations of multiple if statements and while loops, single/split/multiple lines, line separators, etc.). Older versions of mIRC fail about a third of these test cases. This change has the potential to affect all existing scripts, so I will be including it in the next public beta for testing to see how it works out. If all goes well, I will include the change in the next release.
Here's a slight convolution I like
byte $iif($1,) | while ($v1 >= 1000) $iif($calc($v1 /1024),) | return $round($v1,2)
Unfortunately the fix broke at least one case:
alias testloop {
var %a 1
if (1 == 2) noop
else { while (%a <= 5) var -s %a %a + 1 }
}
This worked in the past.
indeed.
It would seem that /while requires { }'s around its action, even if there's only a single action, if it's enclosed inside any other { }'s from an if/else/other while.
testloop {
var %a = 1, %b = 1, %c = 1
if (1) { while (%a <= 5) inc -s %a }
while (%a > 1) { while (%b <= 5) inc -s %b | dec -s %a }
{ while (%c <= 5) inc -s %c }
}
Seems all 3 cases fail to loop the incrementing of the variable.
Thanks, I was able to reproduce this issue. I have added the above examples to my while loop test cases. The fix for this issue was a little trickier and needed a few more changes to the parser code but it now passes all of the test cases. This will be in the next beta.
Good, here is one more example failing, to add to the test cases:
alias custom echo -s $1
alias testloop { while ($1) tokenize 32 $2- $custom($v1) }
Thanks, the new beta handles your test case as well, so that looks good.
Odd. This worked in B4 but not B5.
markasread { var %i = 1 | WHILE ($scon(%i)) { scon %i | var %j = 1 | WHILE ($window(*,%j).wid) { window -g0 @ $+ $v1 | inc %j } | inc %i } }
...
Actually, many of my scripts aren't working.
Thanks, this has been fixed for the next beta.