mIRC Home    About    Download    Register    News    Help

Print Thread
#70076 02/02/04 10:46 AM
Joined: Feb 2004
Posts: 1
X
Xyber Offline OP
Mostly harmless
OP Offline
Mostly harmless
X
Joined: Feb 2004
Posts: 1
In a few common scripting languages, for() command exists.

Here's how it works:
for(start; condition, result)
for(%x = 1; %x < 10, %x++) { action }

It would be a great help if this command exists in future versions of mIRC.

Thanks.

Joined: Dec 2003
Posts: 219
F
Fjord artisan
Offline
Fjord artisan
F
Joined: Dec 2003
Posts: 219
same as:

%x = 1
/while (%x < 10) {
action
/inc %x
}

but a little bit longer to type :P

Joined: Mar 2003
Posts: 1,271
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
I don't mind if it is added, I just doubt it will. Khaled long ago created while loops, if he was going to add for loops, why not add them there?


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Joined: Mar 2003
Posts: 32
P
Pap Offline
Ameglian cow
Offline
Ameglian cow
P
Joined: Mar 2003
Posts: 32
and while he's at it,

foreach()

there are subtle differences between while(), for(), and foreach() loops, which I don't feel the need to explain right now.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
ForEach would only work with an array of some sort, which mIRC doesn't have.

The closest it could do is enumerate a function like $nick(#chan,%i)... in which case you can do this.

var %i = 1
WHILE $nick(#chan,%i) {
echo -a $ifmatch
inc %i
}

Easy Pie.

ForEach could never specify which parameter of $nick should be incrimented.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
The thing about FOR and FOREACH loops as i see it is there is more to remember and the interpreter doesnt really remember much, it just chugs along interpreting what ever it finds as it finds it. ill give you this as an example.
Code:
var %c = 1
var %i = 1
var %m = 500
while (%c &lt; %m) {
  echo -a %c
  inc %c %i
  dec %m %i
  inc %i
} 
 

results : 1 2 4 7 11 16 22 29 37 46 56 67 79 92 106 121 137 154 172 191 211 232

now a QBASIC for loop (sorry i didnt have anything else here)
Code:
i = 1
m = 500
for c = 1 to m step i
  print c
  m = m - i
  i = i + 1
next
 

results : 1 2 3 4 5 .... 98 99 500

which is mirc ment to do, the "1 2 4 ..." or the "1 2 3 ..." if its the "1 2 3 ..." then mirc must store the original valuie of %m (max value) & %i (incrementor) which pretty much it just doesnt do, it comes back and interprets the line again to see if the condition valid or false, but with a FOR it would need to have stored the max value and the incrementor and uses them again.

The above fact that while loops run comparing a varable/modifable arguemnet for repititon on its own makes the while loop a superset command to for and foreach,
Anything a for or a foreach can do a while can do also, while a for or foreach cant reproduce what a while loop can (with out some tricky coding)

Joined: Mar 2003
Posts: 32
P
Pap Offline
Ameglian cow
Offline
Ameglian cow
P
Joined: Mar 2003
Posts: 32
you are correct that anything a for/foreach() loop can do a while() loop can do, but sometimes a for() loop just makes for much nicer/cleaner code, which is especially useful when going through other people's code.

oh well, just a though. i don't see any obvious disadvantage per se to implementing such a feature into mirc.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
i don't see any obvious disadvantage per se to implementing such a feature into mirc.


Umm i thought i just explained a disadvantage, the fact that the interpreter doesnt store specifics about previous commands, so a for loop would not function as for loops do, but it would have to be evaluated each time.
ex.

Code:
1. var %c = 1
2. var %i = 1
3. var %m = 500
4. /for %c = %c to %m step %i {
5.   echo -a %c
6.   dec %m %i
7.   inc %i
8. }
 


code would run as follows.
1. c = 1
2. i = 1
3. m = 500
4. c = 1
5. echo -a 1
6. m = 499
7. i = 2
8. go back to 4. (and assuming it knows its in the loop already)
4. c = 3 (since i = 2 and repeat since c is less than 499 m)
5. echo -a 3

now we have a new strain of results "1 3 6 10...".

The only way a for loop would work as there ment to is if u specificly avoid playing with the stepper value and the stopper value, which compiled (and semi compiled) languages keep track of seperately from the values they were sourced from.

On a personal level I dont find a for loop any clear to read in code than a while loop, but thats just IMO.

Joined: Apr 2003
Posts: 210
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Apr 2003
Posts: 210
Quote:
the fact that the interpreter doesnt store specifics about previous commands,


I'm sure mIRC must do that atleast for some commands... And even if it doesn't, Why couldn't it be made to do it in the case of FOR loops?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:

I'm sure mIRC must do that atleast for some commands...

Can you name one, I cant think of any, The only memorizing of data i have seen is if a command is callling subroutines as either routines or identifiers.


Quote:

And even if it doesn't, Why couldn't it be made to do it in the case of FOR loops?


Well it wouldnt be common, but amagine the interpreter storing the loop information only to return to the top and find there now is no forloop there. ex:
Code:
 
blah {
  $1- {
    echo -s %fred
    if (%fred == %barney) tokenize 32 if ( %fred != %barney )
  }
}
 


/set %barney 7
/blah for %fred = 1 to 55

On the end of the 7th rep the FOR loop no longer exists.

as i said the interpretor just chugs along doing what ever it encounters next, it doesnt remeber loops etc

PS: i well say that replacing the loop control with a IF is the far edge of coding practices but things lik eit are possable.

Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Well there is no need to discuss these things anyway, this would be Khaled's business (although I guess he's already answered the /for question).


* cold edits his posts 24/7
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
lol, oh yes lets not discuss something on a message board that would be bad form old chap. smile

Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Since this was heavily discussed before, even low-level things that are up to K. (instead of the ideas themselves), yes that would be bad.


* cold edits his posts 24/7
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Not to get off on a tangent, but a foreach that works on tokenized string would be nice. Don't quote me on syntax, but something to the effect of

Code:
var %tokens = a.b.c.d.e.f.g
foreach (%tokens as %tok, 46) {
  echo %tok
}


compared to

Code:
var %tokens = a.b.c.d.e.f.g, %a = 1
while ($gettok(%tokens, %a)) {
  echo $ifmatch
  ; this assuming you are only using it in this block. If you should sue it in a nested
  ; condition,  you would need another line:
  ; var %tok = $ifmatch
}


Again, don't know how you'd get the params to be specified, but you have it disassemble a tokenized string into a variable, and tell it what character you want it tokenized by.


-KingTomato
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Maybe, although I think this is quite enough:
Code:
tokenize 46 a.b.c.d.e.f.g
while ($0) {
  [...] $1 [...]
  tokenize 32 $2-
}


* cold edits his posts 24/7

Link Copied to Clipboard