mIRC Home    About    Download    Register    News    Help

Print Thread
nested while loops on one line bug? #105904 22/12/04 02:52 AM
Joined: May 2004
Posts: 3
T
triple Offline OP
Self-satisified door
OP Offline
Self-satisified door
T
Joined: May 2004
Posts: 3
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
  }
}

Re: nested while loops on one line bug? #105905 22/12/04 05:55 AM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
This has been reported before. Look at: http://forums.mirc.com/showflat.php?Number=78644

Re: nested while loops on one line bug? #105906 23/12/04 12:06 AM
Joined: May 2004
Posts: 3
T
triple Offline OP
Self-satisified door
OP Offline
Self-satisified door
T
Joined: May 2004
Posts: 3
ah ok, sorry

Re: nested while loops on one line bug? [Re: triple] #250021 30/12/14 07:49 AM
Joined: Feb 2003
Posts: 2,785
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,785
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.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: nested while loops on one line bug? [Re: Raccoon] #250543 19/01/15 11:50 PM
Joined: Dec 2002
Posts: 5,020
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,020
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.

Re: nested while loops on one line bug? [Re: Khaled] #250544 19/01/15 11:53 PM
Joined: Feb 2003
Posts: 2,785
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,785
Here's a slight convolution I like smile

byte $iif($1,) | while ($v1 >= 1000) $iif($calc($v1 /1024),) | return $round($v1,2)


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: nested while loops on one line bug? [Re: Khaled] #251117 10/02/15 01:40 AM
Joined: Jul 2006
Posts: 3,829
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,829
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: nested while loops on one line bug? [Re: Wims] #251118 10/02/15 02:39 AM
Joined: Feb 2003
Posts: 2,785
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,785
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.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: nested while loops on one line bug? [Re: Raccoon] #251135 10/02/15 05:45 PM
Joined: Dec 2002
Posts: 5,020
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,020
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.

Re: nested while loops on one line bug? [Re: Khaled] #251141 10/02/15 09:44 PM
Joined: Jul 2006
Posts: 3,829
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,829
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) }


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: nested while loops on one line bug? [Re: Wims] #251241 12/02/15 12:22 PM
Joined: Dec 2002
Posts: 5,020
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,020
Thanks, the new beta handles your test case as well, so that looks good.

Re: nested while loops on one line bug? [Re: Khaled] #251262 13/02/15 11:24 AM
Joined: Feb 2003
Posts: 2,785
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,785
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.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: nested while loops on one line bug? [Re: Raccoon] #251263 13/02/15 12:28 PM
Joined: Dec 2002
Posts: 5,020
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,020
Thanks, this has been fixed for the next beta.

Re: nested while loops on one line bug? [Re: Khaled] #269642 23/11/21 11:54 PM
Joined: Jan 2004
Posts: 1,640
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,640
Another test case to add to the list. It looks like the "suh" alias from 2004 works correctly now, however it seems that the nested while's on 1 line are preventing the /break command from working.

Code
//var %i 5 | while (%i) { var %t $ticks + 1000 | while (%t > $ticks) { noop } | echo -a $asctime i= %i | if (%i == 3) goto label | dec -s %i } | echo -a test1 | :label | echo -a test2



Code
//var %i 5 | while (%i) { var %t $ticks + 1000 | while (%t > $ticks) { noop } | echo -a $asctime i= %i | if (%i == 3) break | dec -s %i } | echo -a test1 | :label | echo -a test2



The 1st command correctly goto's to the label when %i reaches 3.

In old behavior, the 2nd of the above commands did a 'normal' loop exit at the bottom of the loop, immediately after decrementing %i to 4, instead of waiting until %i reached 3.

It should exit the loop immediately after displaying the message showing %i was now 3, but instead it now it repeats the outer while() repeatedly until %i reaches zero.

--

The above issue might be related to the issue of the {} required around the /noop for the inner while, as mentioned in https://forums.mirc.com/ubbthreads....e-loops-on-single-line-issues#Post264499


edit: seems /continue is being ignored same as /break is. The continue should prevent the /echo from being displayed at all:

//var %i 3 | while (%i) { dec -s %i | var %t $ticks + 1000 | while (%t > $ticks) { noop } | continue | echo -a this should not show }



Last edited by maroon; 24/11/21 12:10 AM.