mIRC Homepage
Posted By: triple nested while loops on one line bug? - 22/12/04 02:52 AM
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.

Code:
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
  }
}
Posted By: Sigh Re: nested while loops on one line bug? - 22/12/04 05:55 AM
This has been reported before. Look at: https://forums.mirc.com/showflat.php?Number=78644
Posted By: triple Re: nested while loops on one line bug? - 23/12/04 12:06 AM
ah ok, sorry
Posted By: Raccoon Re: nested while loops on one line bug? - 30/12/14 07:49 AM
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.
Posted By: Khaled Re: nested while loops on one line bug? - 19/01/15 11:50 PM
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.
Posted By: Raccoon Re: nested while loops on one line bug? - 19/01/15 11:53 PM
Here's a slight convolution I like smile

byte $iif($1,) | while ($v1 >= 1000) $iif($calc($v1 /1024),) | return $round($v1,2)
Posted By: Wims Re: nested while loops on one line bug? - 10/02/15 01:40 AM
Unfortunately the fix broke at least one case:
Code:
alias testloop {
  var %a 1
  if (1 == 2) noop
  else { while (%a <= 5) var -s %a %a + 1 }
}
This worked in the past.
Posted By: Raccoon Re: nested while loops on one line bug? - 10/02/15 02:39 AM
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.
Posted By: Khaled Re: nested while loops on one line bug? - 10/02/15 05:45 PM
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.
Posted By: Wims Re: nested while loops on one line bug? - 10/02/15 09:44 PM
Good, here is one more example failing, to add to the test cases:

Code:
alias custom echo -s $1
alias testloop { while ($1) tokenize 32 $2- $custom($v1) }
Posted By: Khaled Re: nested while loops on one line bug? - 12/02/15 12:22 PM
Thanks, the new beta handles your test case as well, so that looks good.
Posted By: Raccoon Re: nested while loops on one line bug? - 13/02/15 11:24 AM
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.
Posted By: Khaled Re: nested while loops on one line bug? - 13/02/15 12:28 PM
Thanks, this has been fixed for the next beta.
© mIRC Discussion Forums