mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
FOR loop #222851 06/07/10 07:40 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
I think mIRC may have a FOR loop...
What do you think about that?


Nothing...
Re: FOR loop [Re: Masoud] #222852 06/07/10 07:48 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I would love to see this added, but maybe with a "," delimiter instead of ";" to match the rest of the language:

Code:
for (var %x = 1,%x <= 10,inc %x) {
  echo -a %x
}


Output:

1
2
3
4
5
6
7
8
9
10

I also think the first parameter for for () should accept all variations of the var/set commands:

Code:
for (var %x = 1,%x <= 10,inc %x) {
  echo -a %x
  ; %x is local to the for loop so this will display.
}
echo -a %x
; this will throw an error unless %x is a global variable, as the local variable %x above was unset upon the termination of the loop.


Code:
for (set -u %x 1,%x <= 10,inc %x) {
  echo -a %x
}
echo -a %x
; Both %x 's will display but %x will unset at the end of the current code block.


Code:
for (set %x 1,%x <= 10,inc %x) {
  ; %x is global here and will return a value until it is unset. 
}

Re: FOR loop [Re: hixxy] #222858 06/07/10 08:27 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
It's good hear that. I hope that Khaled will doing something about this good and useful feature wink


Nothing...
Re: FOR loop [Re: Masoud] #222860 06/07/10 10:12 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Just as a note... It's been suggested many times in the past, so I wouldn't get your hopes up on it being added really soon. Maybe it will, but it appears to be either low down on Khaled's to-do list or he has decided not to do it at all.

FOR can be useful, but it really isn't that much different to use a WHILE loop. Yes, it's more lines, but the end result in most situations will be the same and I have a feeling that it wouldn't even be more efficient because it will still be executing the same commands.

I don't much care either way. It's so common in programming and scripting languages that I agree it should also be here, but it's so easy to do the same thing with WHILE that I don't think there's any rush to get it added either.


Invision Support
#Invision on irc.irchighway.net
Re: FOR loop [Re: Masoud] #222861 06/07/10 10:42 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I would also like to see switch/case blocks:

Code:
var %x = 10
switch (%x) {
  case (1) { ; %x = 1 }
  case (> 5) { ; %x is more than 5 }
  case (<= 5) { ; %x is less than 6 }
}

Re: FOR loop [Re: Riamus2] #222862 06/07/10 10:53 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
Yes, I know what i said can be suggested many times before. But i just said my suggestion and opinion.

What you just said is right but i have a question from you: "Why don't you use 'goto' loop instead of 'while' loop?"

The answer is pretty easy: "Because 'while' is doing much better and it takes less codes and less mistakes."

So YES, they are the same. BUT when there is a better feature than 'while' (Which is 'for') Why shouldn't we be able to use it? By the way, I don't really think that is SO HARD to exert for Khaled. He can set it up so easily.

What do you think now Riamus2?


Nothing...
Re: FOR loop [Re: hixxy] #222863 06/07/10 10:55 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
Yeah hixxy, that's a really good suggestion/idea. And i like to use a 'try/catch' blocks too!


Nothing...
Re: FOR loop [Re: hixxy] #222870 07/07/10 07:18 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: hixxy

I also think the first parameter for for () should accept all variations of the var/set commands:


hey hixxy :P i think it would be more sensible to have the first (and third) parameter function equivalent to how the command parameter in $findfile() does; it would be more aligned with for() implementations in other languages, wouldn't be entirely out of place, and would make the command suitable for a wider variety of applications


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: FOR loop [Re: hixxy] #222872 07/07/10 07:54 AM
Joined: Dec 2002
Posts: 122
S
STING Offline
Vogon poet
Offline
Vogon poet
S
Joined: Dec 2002
Posts: 122
Originally Posted By: hixxy
I would also like to see switch/case blocks:

Code:
var %x = 10
switch (%x) {
  case (1) { ; %x = 1 }
  case (> 5) { ; %x is more than 5 }
  case (<= 5) { ; %x is less than 6 }
}


Agreed!

Re: FOR loop [Re: Masoud] #222891 07/07/10 10:26 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
I wanted to get at least an answer from Khaled and read his explanation about this. (Or maybe he already respond in the same other topics. I don't know.)
By the way, I didn't got any answers.
Whatever, Have fun guys.


Nothing...
Re: FOR loop [Re: Masoud] #222895 07/07/10 11:00 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
So you know, Khaled rarely replies to feature suggestion topics. He'll reply about bugs either asking for more information or to say that it's fixed for the next release or sometimes to explain why it's not a bug or how to get around it. He also responds to some of the other forums regarding connection issues or requesting help with mIRC. But he just doesn't usually respond in this forum or the script help forum. So don't take that to mean that he isn't reading or doesn't agree with your suggestions.


Invision Support
#Invision on irc.irchighway.net
Re: FOR loop [Re: Riamus2] #222896 07/07/10 11:22 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
Yeah, I know that BUT "Reading topics" is not enough. mIRC Users in here need answers. ( I don't mean that he should reply to all of the topics, but this kind of topics are different.)
If people know that they just wasting their time in here without any answers, then they won't post anything in here and it's a dead-end for this primary mIRC's forum...


Nothing...
Re: FOR loop [Re: Masoud] #222897 08/07/10 12:15 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Your opinion is noted, but it probably won't change the way Khaled handles feature suggestions.

If you consdier suggesting something a "waste of time", don't suggest it; simple as that. Suggesting a feature is not a guarantee that it will be implemented-- you knew that before you posted (you should have, anyway, since that's how "suggestions" tend to work). Therefore, Khaled's response or lack thereof won't change anything. Furthermore, it's probable that Khaled does not respond to these threads because:

1) There are no plans to implement the suggestion (ever) and he finds no reason to have to discuss his decision.
2) He's responded to a thread on the same suggestion before and does not need to respond to the same issue again.
3) He does not want to commit to implementing (or not implementing) a feature that may turn out to be too difficult or time consuming to implement properly.

With these reasons in mind, Khaled often does not respond to feature suggestions. I'm sure you can accept that.

Note that the feature suggestions forum is in no way a "waste of time". Just about every feature Khaled has ever implemented has originated from this forum, so your claim that not knowing whether a suggestion will be implemented makes posting a waste of time, is categorically false. People don't post suggestions so they can see Khaled respond to them. They post suggestions so that they can make it into mIRC. The only way you waste your time is if the feature you suggest will never be implemented-- which, by the way, pretty much sums up all the suggestions in this thread, which have been suggested many times before but never been implemented.

As far as the suggestions actually go: for loops are just glorified while loops, which already exist in mIRC. There's no real need for the syntactic sugar, since you don't even really save on number-of-bytes. switch cases can be useful, but again, they're mostly just syntactic sugar and are likely too complicated for Khaled to focus on with so many other features to deal with. Try/catch is pretty much useless, since mIRC has no concept of exceptions besides the half-baked :error label. For try-catch to work, Khaled would need to create an entire exception handling mechanism, which is relatively difficult and extremely unlikely.

It should also be pointed out that, in general, Khaled does not like to touch the parser much. The last time he did (6.33), he broke /if completely and had to put out another version (6.34) within ~48 hours. Therefore suggestions regarding the parser and the language syntax are generally hard to get through in the first place, and you shouldn't really expect any form of commitment on these.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: FOR loop [Re: argv0] #222912 08/07/10 10:32 PM
Joined: Mar 2010
Posts: 144
Masoud Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Mar 2010
Posts: 144
You got wrong what I meant about the "Wasting time"; I didn't say it's REALLY wasting time... There is a "IF" in the start. (Or maybe my English is weak and I couldn't said that what i meant exactly.)
I'm like-minded by the rest of your comment except of what you said about "/if", What me and some others suggested in here is not really that SO hard thing like "/if"...
By the way, thanks for your time/comment/information.


Nothing...
Re: FOR loop [Re: Masoud] #222932 09/07/10 07:48 PM
Joined: Apr 2010
Posts: 939
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 939
I'd also Like to see a foreach loop:


foreach (string,delimiter) { }
Code:
foreach (this is a string,32) {
  echo -a $fedata
}
would echo:
this
is
a
string


foreach -h (hashtable,<condition>)[.data] { }
Code:
 foreach -h (table,*match item*) {
  echo -a $feitem $fedata
}
echo each matching item, and it's data.
the .data property would have the loop match data


foreach -i (inifile,[topic],<condition>) { }
Code:
foreach -i (inifile,sometopic,*).data {
  echo -a $fetopic $feitem $fedata
}
matches items in an ini file.
the .data property will have the loop match data







I am SReject
My Stuff
Re: FOR loop [Re: FroggieDaFrog] #222934 09/07/10 10:30 PM
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
Posts: 52
All good ideas.
It's true, you could accomplish for with while and switch with ifs, but I'de still like to see 'em implemented, and the foreach idea is AWESOME!
(Of course, you can do "var %x = <condition> | if (%x == case1) { } | elseif (%x == case2) { } ..." <- Switch&cases.)
("tokenize 32 <string> | var %i = 1 | var %word = $ [ $+ [ %i ] ] | while (%word) { echo -a %word | inc %i | var %word = $ [ $+ [ %i ] ] }" <- Foreach, or somwthing like this...this was just something done on the spot... xD)

ziv.

Re: FOR loop [Re: FroggieDaFrog] #222971 11/07/10 05:08 AM
Joined: Feb 2004
Posts: 206
D
Darwin_Koala Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Code:
tokenize delimiter, string
<command> $*

e.g.
Code:
tokenize 32 this is a string
echo -a $*

would echo:
this
is
a
string

I don't have mIRC open, so my syntax on tokenize may be slightly wrong - check the help file.

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Re: FOR loop [Re: Darwin_Koala] #222973 11/07/10 05:28 AM
Joined: Apr 2010
Posts: 939
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 939
Originally Posted By: Darwin_Koala
Code:
tokenize delimiter, string
<command> $*

e.g.
Code:
tokenize 32 this is a string
echo -a $*


First off $* is undocumented so it could be removed at any time without any notification.
Second, try doing multiple commands with $*. To do so, you have to write an alias.
Third, try doing something like:
Code:
tokenize 32 this is an example | if ($* == is) { echo -a $v1 }


I am SReject
My Stuff
Re: FOR loop [Re: FroggieDaFrog] #222975 11/07/10 09:01 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: FroggieDaFrog
I'd also Like to see a foreach loop:


foreach (string,delimiter) { }
Code:
foreach (this is a string,32) {
  echo -a $fedata
}
would echo:
this
is
a
string


foreach -h (hashtable,<condition>)[.data] { }
Code:
 foreach -h (table,*match item*) {
  echo -a $feitem $fedata
}
echo each matching item, and it's data.
the .data property would have the loop match data


foreach -i (inifile,[topic],<condition>) { }
Code:
foreach -i (inifile,sometopic,*).data {
  echo -a $fetopic $feitem $fedata
}
matches items in an ini file.
the .data property will have the loop match data



i like the general idea, but implementation in the nature that you described seems complicated and messy. the notion of a control structure such as the proposed foreach() having these accompanying switches and identifiers is quite bizarre, albeit a novel one :P the task of iterating is not made any simpler since, it seems, a user would be required to understand and be familiar with the behaviour of $gettok, $hfind and $ini to be able to effectively use those that you mentioned. the end result of one of these loops would resemble currently scriptable methods in complexity and size, so it doesn't appear to provide enough added benefit to the scripting language.

i had a similar thought a couple of weeks ago while we were discussing a hypothetical foreach() on EFnet's #mIRC. suggestions were being thrown around and my thoughts gradually converged upon an idea that, at the time, i believed to be epiphanic. what if we could abstract the idea away from association with any particular command or identifier and create a general purpose foreach () that would iterate through a collection of items exactly as $submenu() does (send 1 to the alias/identifier and keep increasing until it returns $null). an example might be:

Code:
foreach ($gettok(%var, $1, 32)) {
  ; $v1 is filled with the return value
}


but quick as the idea came to me, so too was it dismissed as i realized the obvious folly: that it is, for all intents and purposes, equivalent to:

Code:
var %i = 1
while ($gettok(%var, %i, 32) != $null) {
  ; $v1 is filled with the return value
  inc %i
}


i had mentally tweaked and adapted the idea to the point where it resembled, almost entirely, something that is readily available to me already ;D great story right


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: FOR loop [Re: jaytea] #222977 11/07/10 10:28 AM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Originally Posted By: jaytea
Originally Posted By: hixxy

I also think the first parameter for for () should accept all variations of the var/set commands:


hey hixxy :P i think it would be more sensible to have the first (and third) parameter function equivalent to how the command parameter in $findfile() does; it would be more aligned with for() implementations in other languages, wouldn't be entirely out of place, and would make the command suitable for a wider variety of applications


Could do,

But do you think there are many commands other than the variable related ones that have a place in for () ?

Things like this, for example, wouldn't really be very good methods to achieve something:

Code:
var %i = 10 
for (hadd -m test test 1,$hget(test,test) <= %i,hinc test test) {
  echo -a $hget(test,test)
}

Page 1 of 2 1 2