mIRC Home    About    Download    Register    News    Help

Print Thread
Bug in while loop #235625
31/12/11 04:02 AM
31/12/11 04:02 AM
Joined: Jun 2007
Posts: 35
alephresh Offline OP
Ameglian cow
alephresh  Offline OP
Ameglian cow

Joined: Jun 2007
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.
Re: Bug in while loop [Re: alephresh] #235631
31/12/11 02:30 PM
31/12/11 02:30 PM
Joined: Jun 2007
Posts: 35
alephresh Offline OP
Ameglian cow
alephresh  Offline OP
Ameglian cow

Joined: Jun 2007
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.
Re: Bug in while loop [Re: alephresh] #235645
01/01/12 07:58 PM
01/01/12 07:58 PM
Joined: Oct 2010
Posts: 27
D
Desolator Offline
Ameglian cow
Desolator  Offline
Ameglian cow
D

Joined: Oct 2010
Posts: 27
why are you trying to use $& in a loop anyway?

Re: Bug in while loop [Re: Desolator] #235649
01/01/12 09:18 PM
01/01/12 09:18 PM
Joined: Oct 2003
Posts: 3,918
Montreal, QC, Canada
A
argv0 Offline
Hoopy frood
argv0  Offline
Hoopy frood
A

Joined: Oct 2003
Posts: 3,918
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"
Re: Bug in while loop [Re: Desolator] #235650
02/01/12 04:23 AM
02/01/12 04:23 AM
Joined: Jun 2007
Posts: 35
alephresh Offline OP
Ameglian cow
alephresh  Offline OP
Ameglian cow

Joined: Jun 2007
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.
Re: Bug in while loop [Re: alephresh] #235651
02/01/12 08:14 AM
02/01/12 08:14 AM
Joined: Oct 2003
Posts: 3,918
Montreal, QC, Canada
A
argv0 Offline
Hoopy frood
argv0  Offline
Hoopy frood
A

Joined: Oct 2003
Posts: 3,918
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"
Re: Bug in while loop [Re: alephresh] #237949
15/06/12 02:38 PM
15/06/12 02:38 PM
Joined: Jun 2007
Posts: 35
alephresh Offline OP
Ameglian cow
alephresh  Offline OP
Ameglian cow

Joined: Jun 2007
Posts: 35
Thought I might bump this.


Desired: right alignment of text; consecutive spaces in /command args; Ctrl+A in custom dialogs.
Re: Bug in while loop [Re: alephresh] #238416
24/07/12 12:09 PM
24/07/12 12:09 PM
Joined: Dec 2002
Posts: 4,449
London, UK
Khaled Offline

Hoopy frood
Khaled  Offline

Hoopy frood

Joined: Dec 2002
Posts: 4,449
London, UK
Thanks this issue has been fixed for the next version.

Re: Bug in while loop [Re: Khaled] #263859
01/10/18 04:13 PM
01/10/18 04:13 PM
Joined: Jun 2007
Posts: 35
alephresh Offline OP
Ameglian cow
alephresh  Offline OP
Ameglian cow

Joined: Jun 2007
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.
Re: Bug in while loop [Re: alephresh] #263873
03/10/18 09:28 AM
03/10/18 09:28 AM
Joined: Dec 2002
Posts: 4,449
London, UK
Khaled Offline

Hoopy frood
Khaled  Offline

Hoopy frood

Joined: Dec 2002
Posts: 4,449
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.