mIRC Home    About    Download    Register    News    Help

Topic Options
#262134 - 05/01/18 11:04 PM (nvm!) Nested while loops on single line issues?
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2600
Dear Khaled, (edit: nevermind)

Do you expect that there should still be unresolved issues regarding simple nested while-loops (or if-checks) when scripted as single line code, or editbox code?

I don't recall if you declared these issues resolved or not.

Example:
Code:
tickstest1 {
  var %n = 100, %max = 0, %ticks, %i
  while (%n > 0) {
    set %i 1
    set %ticks $ticks
    while ($ticks == %ticks) inc %i
    if (%i > %max) set %max %i
    dec %n
  }
  echo -a * tickstest1: n= %n , i= %i , max= %max
}

tickstest2 { var %n = 100, %max = 0, %ticks, %i | while (%n > 0) { set %i 1 | set %ticks $ticks | while ($ticks == %ticks) inc %i | if (%i > %max) set %max %i | dec %n } | echo -a * tickstest2: n= %n , i= %i , max= %max }

* tickstest1: n= 0 , i= 718 , max= 786
* tickstest2: n= 98 , i= 1 , max= 268

I've tried many many variants of the above code. while (%n) vs while (%n > 0), with and without { } for the inner /while, with and without the /if (%i > %max) code, using /set instead of /var, etc. I don't get any nested while loops to work on a single line, so I assume this was never resolved or marked as unfixable?

__

Edit: maroon found that wrapping /inc %i in { } braces makes the single-line code work. Some how I assumed that did not work for me either. So I guess my question is moot but I'll leave this here to the oddities encountered, and maroon's credit.

tickstest3 { var %n = 100, %max = 0, %ticks, %i | while (%n > 0) { set %i 1 | set %ticks $ticks | while ($ticks == %ticks) { inc %i } | if (%i > %max) set %max %i | dec %n } | echo -a * tickstest2: n= %n , i= %i , max= %max }


Edited by Raccoon (05/01/18 11:34 PM)
Edit Reason: is not a maroon.
_________________________
Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Top
#262136 - 05/01/18 11:47 PM Re: (nvm!) Nested while loops on single line issues? [Re: Raccoon]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
Khaled did fix some issues with nested while loop on single line but this is just another issue, I don't see why you are nevermind'ing it, this is a bug and should work just fine given that it works with multiple lines.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#264499 - 09/12/18 03:26 AM Re: (nvm!) Nested while loops on single line issues? [Re: Wims]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1158
I stumbled across this bug again, having forgotten that this issue had come up earlier.

To summarize what my testing shows, the bug is trigged where there's a /while nested inside another /while. For this to happen, the interior nested /while consists of a single command not enclosed in brackets, and is either in an editbox or is on the same scriptline line as the end-bracket ending the exterior /while. So 2 lines is enough to avoid the early exit, as long as the command is split in one of the right places.

This example alias shows it doesn't matter whether the end-bracket is on a 'normal' next-line, or is an extension of the existing line using $& to continue the same command on the next row. The red countdown exits early unless brackets are added to enclose the /noop. But the purple and green countdowns don't exit early, because the nested /while is split across the two lines:

Code:
alias nested_while {
  var %c $ctime , %i 5 | while (%i) { while (%c == $ctime) noop | var %c $v2 | echo 4 -a i= %i $time | dec %i } | echo -a finish $time
  var %c $ctime , %i 5 | while (%i) { while (%c == $ctime) noop
  var %c $v2 | echo 6 -a i= %i $time | dec %i } | echo -a finish $time
  var %c $ctime , %i 5 | while (%i) { while (%c == $ctime) noop | var %c $v2 | ec $+ $&
    ho 3 -a i= %i $time | dec %i } | echo -a finish $time
}

Top
#264501 - 09/12/18 04:47 AM Re: (nvm!) Nested while loops on single line issues? [Re: Wims]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2600
Ouims: I don't consider it a bug because Khaled has already asked us kindly not to complain about incongruities with brace formatting omissions.

We know that WHILE is a pre-parser syntax and not regular a command. If it needs braces to support one-line nesting, then it needs braces to support one-line nesting.
_________________________
Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Top
#264505 - 09/12/18 01:26 PM Re: (nvm!) Nested while loops on single line issues? [Re: Raccoon]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
Ok, well that's still a bug as far as I'm concerned so I will report it as such with maroon's addition, or maybe he will report that himself.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#264507 - 09/12/18 03:13 PM Re: (nvm!) Nested while loops on single line issues? [Re: maroon]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 4449
Loc: London, UK
Thanks for your post. As you noted, this issue has been discussed before and the solution is to use {} brackets. This issue is already on my to-do list.

Top