mIRC Home    About    Download    Register    News    Help

Topic Options
#235625 - 31/12/11 04:02 AM Bug in while loop
alephresh Offline
Ameglian cow

Registered: 01/06/07
Posts: 35
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
_________________________
Desired: right alignment of text; consecutive spaces in /command args; Ctrl+A in custom dialogs.

Top
#235631 - 31/12/11 02:30 PM Re: Bug in while loop [Re: alephresh]
alephresh Offline
Ameglian cow

Registered: 01/06/07
Posts: 35
Actually...

Code:
alias test {
  var %i = 0
  while ((%i < 10) && $&
    (0 == 0)) {
     inc %i
  }
}
_________________________
Desired: right alignment of text; consecutive spaces in /command args; Ctrl+A in custom dialogs.

Top
#235645 - 01/01/12 07:58 PM Re: Bug in while loop [Re: alephresh]
Desolator Offline
Ameglian cow

Registered: 13/10/10
Posts: 27
why are you trying to use $& in a loop anyway?

Top
#235649 - 01/01/12 09:18 PM Re: Bug in while loop [Re: Desolator]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#235650 - 02/01/12 04:23 AM Re: Bug in while loop [Re: Desolator]
alephresh Offline
Ameglian cow

Registered: 01/06/07
Posts: 35
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).
_________________________
Desired: right alignment of text; consecutive spaces in /command args; Ctrl+A in custom dialogs.

Top
#235651 - 02/01/12 08:14 AM Re: Bug in while loop [Re: alephresh]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#237949 - 15/06/12 03:38 PM Re: Bug in while loop [Re: alephresh]
alephresh Offline
Ameglian cow

Registered: 01/06/07
Posts: 35
Thought I might bump this.
_________________________
Desired: right alignment of text; consecutive spaces in /command args; Ctrl+A in custom dialogs.

Top
#238416 - 24/07/12 01:09 PM Re: Bug in while loop [Re: alephresh]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 4297
Loc: London, UK
Thanks this issue has been fixed for the next version.

Top
#263859 - 01/10/18 05:13 PM Re: Bug in while loop [Re: Khaled]
alephresh Offline
Ameglian cow

Registered: 01/06/07
Posts: 35
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 )
_________________________
Desired: right alignment of text; consecutive spaces in /command args; Ctrl+A in custom dialogs.

Top
#263873 - 03/10/18 10:28 AM Re: Bug in while loop [Re: alephresh]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 4297
Loc: London, UK
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.

Top