mIRC Homepage

Bug in while loop

Posted By: alephresh

Bug in while loop - 31/12/11 04:02 AM

Hi,

Code:
alias test {
  var %row = 0
  while (%row < 5) {
    var %col = 0
    while (%col < 5) {
      if (0 == 0) {
        inc %col
        while ((%col < 5) && $&
          (0 == 0)) {
          inc %col
        }
      }
      inc %col
    }
    inc %row
  }
}

I get the following error when the innermost loop finishes its first step:

* /while: loop not found (line 9, remote.ini)

Removing the $& line break makes the problem go away.

mIRC version: 7.22

Thanks smile
Posted By: alephresh

Re: Bug in while loop - 31/12/11 02:30 PM

Actually...

Code:
alias test {
  var %i = 0
  while ((%i < 10) && $&
    (0 == 0)) {
     inc %i
  }
}
Posted By: Desolator

Re: Bug in while loop - 01/01/12 07:58 PM

why are you trying to use $& in a loop anyway?
Posted By: argv0

Re: Bug in while loop - 01/01/12 09:18 PM

The same reason you would use $& anywhere else. It seems legitimate to want to use $& in a while/if condition. Note that $& works in if conditions:

Code:
alias testif {
  if ((0 == 0) && $&
    (1 == 1)) {
    echo -a this works in 7.22
  }
}


So it should be equally valid in while conditions.

I should point out that even though the while loop fails to "loop", the condition part does actually work. In other words:

Code:
alias test {
  var %i = 0
  while ((%i < 10) && $&
    (0 == 0)) {
     echo -a This works
     inc %i
  }
}


Does echo "This works" once before the error is displayed. It just fails to jump back to the beginning of the loop and iterate multiple times. I imagine the bug is that mIRC thinks the continuation line for the loop is on line 4 of that alias because that's where it ends, so it jumps back there and doesn't find the /while command. mIRC should register the "continuation line" as the beginning of the while line, not the end.
Posted By: alephresh

Re: Bug in while loop - 02/01/12 04:23 AM

What argv0 said.

$& is for improving code readability. If code lines are too long, you may be forced to scroll horizontally, which is undesirable. What I showed here was just demo code, but originally the loop condition line was very long. (I probably should've written it more elegantly, but that's a different story. smile )

Actually, I'm seriously surprised no one's ever bumped into such a general use case (myself included).
Posted By: argv0

Re: Bug in while loop - 02/01/12 08:14 AM

Originally Posted By: alephresh
Actually, I'm seriously surprised no one's ever bumped into such a general use case (myself included).


My guess is most people aren't aware of $&. That, coupled with the fact that there tend to be better ways to split statements up into multiple lines, and the fact that most scripters don't seem to care how long their lines are (see some pastes in the Scripting section of this forum for examples of rampant long line abuse), lead to a pretty low chance of this having been used in a while loop by someone who actually spends the time to report bugs. I should point out, the people who spend time to report bugs are already in the minority smile
Posted By: alephresh

Re: Bug in while loop - 15/06/12 02:38 PM

Thought I might bump this.
Posted By: Khaled

Re: Bug in while loop - 24/07/12 12:09 PM

Thanks this issue has been fixed for the next version.
Posted By: alephresh

Re: Bug in while loop - 01/10/18 04:13 PM

Originally Posted By: Khaled
Thanks this issue has been fixed for the next version.

Thanks! There's no error now, but there's a logical issue - this only echoes "1":

Code:
alias test {
  var %i = 0
  while ((%i < 10) && $&
    (0 == 0)) {
     inc %i
     echo -ag %i
  }
}

(It only took me 6 years to check the fix... smile )
Posted By: Khaled

Re: Bug in while loop - 03/10/18 09:28 AM

Thanks for your bug report. This is a tricky fix as $& parsing takes place in a specific point in the parser, so it has had to be integrated into while loop parsing, which is much more complicated. I have implemented a fix for the next beta but it will need testing.
© 2019 mIRC Discussion Forums