mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
For Loops #62269 29/11/03 10:46 PM
Joined: Nov 2003
Posts: 1
V
vardhan_ Offline OP
Mostly harmless
OP Offline
Mostly harmless
V
Joined: Nov 2003
Posts: 1
mIRC should include for loops. This is for those who are wondering what the heck a FOR loop is..

for (starting command;condition;ending command) {
command
}

Example:

for (set %x 1;%x <= 16;inc %x) {
echo -a %x
}

The above command is the same as:

set %x 1
while (%x <= 16) {
echo -a %x
inc %x
}


o.O
Re: For Loops #62270 29/11/03 10:58 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
.
Please Search Before posting feature suggestions

#1
#2
Skip A Few
#99
#100


-KingTomato
Re: For Loops #62271 04/12/03 12:14 AM
Joined: Dec 2002
Posts: 31
N
Netchelandorious Offline
Ameglian cow
Offline
Ameglian cow
N
Joined: Dec 2002
Posts: 31
I doubt it would be any faster since this is a scripting language... each command is evaluated as it is executed. The only thing it would improve is by giving the scripter less ways to screw up his script (such as by forgetting to increment his variable or setting it initially). If anything, it would likely be SLOWER for having to ignore the initialize setting each time around after the first. Logically, a FOR loop is no different than a WHILE loop in this manner. It still has to execute var %x = 1, still has to check the condition each time around, and still has to inc %x 1 each time. Except for white space, scripting errors and the FOR loop having to ignore the initializer for each additional loop, they are no different.

Re: For Loops #62272 04/12/03 03:08 AM
Joined: Apr 2003
Posts: 426
neophyte Offline
Fjord artisan
Offline
Fjord artisan
Joined: Apr 2003
Posts: 426
But just look at how neat the for loop looks! *INSERT BIG CHEESY GRIN*

:P


--------
mIRC - fun for all the family (except grandma and grandpa)
Re: For Loops #62273 04/12/03 04:04 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
not true. Some conditions would only have to be parsed once. for example the incrememnt itself would be done in memory by mIRC. Using a while loop you have to manually include /inc %incvar wich means mIRC has to parse that command on each iteration _then_ perform the increment. Using for mIRC would handle it in memory and you dont have to include it. In some cases such as leaving off values they can be ignored entirely and not parsed at all. I Think for would be heaps faster than a while in comparison.

If it is added i would like to see multiple conditionals (added to while as well) such as

for (whatever;(some test) && (some other test);inc it) {
code
}


Have Fun smile
Re: For Loops #62274 04/12/03 01:11 PM
Joined: Apr 2003
Posts: 426
neophyte Offline
Fjord artisan
Offline
Fjord artisan
Joined: Apr 2003
Posts: 426
Your suggestion is slightly flawed.
The ; character is currently used as an ignore flag within a script. An alternative solution would be necessary, such as the comma.


--------
mIRC - fun for all the family (except grandma and grandpa)
Re: For Loops #62275 04/12/03 01:42 PM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
it's only used as a comment character if it's at the start of a line


If it ain't broken, don't fix it!
Re: For Loops #62276 04/12/03 08:22 PM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
i was only trying to demonstrate one possibility. I wasnt actually considering any syntax for it at all. I only used ; because thats how for works (and i have no clue how it would work if added to miRC).

Of course it is possible to use a character for different purposes within different situations but most likely an exclusive character would be best.

i didnt see that you post was in reponse to the original posters so i responded (sorry). However i used ; as well : )

Last edited by Narusegawa_Naru; 04/12/03 08:23 PM.

Have Fun smile
Re: For Loops #62277 04/12/03 10:31 PM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
The semi-colon is parsed as a comment such as a # or /* */ in other languages .. it can be placed ANYWHERE within the script. Although syntax is irrelavent to you point it would have to contain commas.

ie

for (blah,blah2,blah)

I seriously doubt that the other identifiers would be re-written for one identifier.

My question is what is the advantage of having a for loop vs the existing while loop?


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62278 04/12/03 10:38 PM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
What? No, ";" must be the first character of the line or the first after a "|" separator in order to be recognized as a comment.


* cold edits his posts 24/7
Re: For Loops #62279 04/12/03 10:57 PM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
not true:

ctcp *:dcc send:*: $iif($len($nopath($filename)) >= 225,halt) ;comment

;ctcp *:dcc send:*: $iif($len($nopath($filename)) >= 225,halt)

ctcp *:dcc send:*: ;$iif($len($nopath($filename)) >= 225,halt)

ALL the above are legal. However placement of the semicolon in the wrong place my break your script


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62280 04/12/03 11:08 PM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
I forgot mentioning about { and }, therefore the lack of them as well.

ctcp *:dcc send:*: $iif($len($nopath($filename)) >= 225,halt) ;comment
'-> this is the only one that, if you say that it works, is an inconsistency or a bug.

;ctcp *:dcc send:*: $iif($len($nopath($filename)) >= 225,halt)
'-> self-explanatory

ctcp *:dcc send:*: ;$iif($len($nopath($filename)) >= 225,halt)
'-> first char: ctcp *:dcc send:*:{ ;$iif($len($nopath($filename)) >= 225,halt) }


Now try "echo -a hi ; bye" and see if what you say applies.
The rule is this, everything else is abnormal.


* cold edits his posts 24/7
Re: For Loops #62281 04/12/03 11:10 PM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
as i was saying i simply used ; in the example to get a point across. Whatever character it uses is what it uses I suppose i wasnt being very PC in the sample.

One such advantage is as I mentioned in my other post. The iterator would only need to be parsed by the script parser once. The rest of its usage would be done in memory. This alone should be anough argument for its implementation. However lets discuss a few more.

With a typical while loop you create a variable and set it to an initial value. thats 1 line of code (can be optimized). The header of a while loop is an additional line so far were up to 2. The incrememnt is yet an additional line (/inc %var) now were up to 3. to ilustrate this lets use a sample

var %inc = 1
while (%inc <= 10) {
code
inc %inc
}

now with a for the declarator and interator is all incorporated into the for's header the same sample using a for (and your suggested comma) would be as follows

for (var %inc = 1,%inc <= 10,inc %inc) {
code
}

overall readability is easier to see. you have fewer lines that need to be parsed (wich is slower)

you could further optimize this by not requireing the var command to declare %inc. since its understood that the first field is a declarator. for example

for (%inc = 1,%inc <= 10,inc %inc) {
code
}

the itterator could be further optimized down to one value such as..

for (%inc = 1,%inc <= 10,+2) {
code
}

in this case %inc is incremented 2 values per ittereation you could use a negative value for decrement. The last example shows that most of the operations on %inc will be done in memory and only parsed once.

Its infinately easier to debug code that uses fewer lines. Certainly code that has several while loops. For nested loops your looking at declaring 2 counters as well as 2 lines for increment/decrememnt and so on.

The goal here is to perform as much "in memory" as possible because its heaps faster than parsing additional lines.


Have Fun smile
Re: For Loops #62282 05/12/03 01:24 AM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
I see your point, however a new loop method is not needed for this.

Perhaps a modification to the while loop can satisfy your request.

ie

while (%inc = 1,%inc <= 10,inc %inc) code


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62283 05/12/03 01:27 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Well now you've just got a for loop that's called a while loop. What's the benefit in that when everyone who's ever programmed any language knows that as a for loop?


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: For Loops #62284 05/12/03 01:28 AM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
Quote:
ctcp *:dcc send:*: $iif($len($nopath($filename)) >= 225,halt) ;comment
'-> this is the only one that, if you say that it works, is an inconsistency or a bug.


The comment works in this case because it is after the event is halted. I have several comments to myself in such a manner.


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62285 05/12/03 01:31 AM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
because this isn't any other programming language. It's the mIRC scripting language.

I can most likely find dozens of other differences between mIRCscript and XYZ programming language, and I'm not even a programer. mIRC is small and fast. Personally I'd like to keep it that way .. I can't see adding a whole new identifier to save a few bits of text.


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62286 05/12/03 01:37 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
But you're not saving a new identifier. With that new syntax for /while you've suggested you've just recreated a for loop, which would inevitably work exactly the same way at it's core. The only difference being, as I said before, that anyone looking for that kind of construct won't be able to find it because they'll be looking for it under /for and not /while.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: For Loops #62287 05/12/03 01:55 AM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
My point is simple smile

I disagree with the addition of a new identifier/command if all it is going to do is save a few keystrokes over an identifier/command that already serves the purpose of the suggested one.

In fact, a custom identifier can be written to satisfy this feature suggestion. Don't you just love re-usable code? grin


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62288 05/12/03 03:00 AM
Joined: Nov 2003
Posts: 33
AdmWiggin Offline
Ameglian cow
Offline
Ameglian cow
Joined: Nov 2003
Posts: 33
ok, i think you guys are kind of not getting a solution to the main question, so i will therefore try to help hows this :
Code:
alias for {
  ;useage :
  ;/for [var] [startvar] [endvar] [command]
  var %var $$1
  set [ %var ] [ $$2 ]
  while ([ %var ] &lt;= $$3) {
    $replace($4-,$1,$eval(%var,1))
    inc [ %var ]
  }
}
DISCLAIMER: works for me! extensive use may cause brain damage...
dont use it for too complex of things... it may not like you ever...


--------------------
I may be insane, but I enjoy it!
Re: For Loops #62289 05/12/03 03:57 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
first off scripting one would completly defeat the entire purpose because hte entire for construct would be parsed making it slower.

Altering the /while command can and will break previous scripts that uses while.

Adding for wont add heaps of size to mIRC no more than any other command/ident.

as for the "saving a few lines" imagine a script using many whiles. Those "few lines" add up. Any script that can be made to be smaller,faster,or more readable im just not seeing a downside here.

How could _anyone_ be against enhancing _any_ language simply because there are workarounds and dirty hacks available?

I do see a bit of your point in that its not one of those "Must have do it right now" items. There are other methods one can use. I would like to see alot of enhancements to the scripting language. Over the last several builds weve seen plenty of enhancements to the UI and functionality such as mserver but little to the language. Except where required to support the new features. for is but one item (switch/case,aggregates,... to name a couple) I would like to see added.

Last edited by Narusegawa_Naru; 05/12/03 04:03 AM.

Have Fun smile
Re: For Loops #62290 05/12/03 03:28 PM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
It's not. It's either an inconsistency, or a bug.

alias blah { $iif(0,halt) ; test }
This gives me "; test" and the "; Unknown command" error.

alias blah { $iif(1,halt) ; test }
This gives me "halt ; test" and *that's* why "; test" is ignored there, because it's treated only as parameters for /halt in the first place.


* cold edits his posts 24/7
Re: For Loops #62291 05/12/03 07:46 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
OK let's compare

Your suggestion. while (%inc = 1,%inc <= 10,inc %inc) code
My (and many thousands of others) suggestion. [color:red]for (%inc = 1,%inc <= 10,inc %inc) code[/color]


What's so terrible about it being called /for instead of hacking /while into something it's not? As for a custom command, it would be slow, awkward, and immensely limited.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: For Loops #62292 27/12/03 01:46 AM
Joined: Apr 2003
Posts: 85
K
katsklaw Offline
Babel fish
Offline
Babel fish
K
Joined: Apr 2003
Posts: 85
Quote:
as for the "saving a few lines" imagine a script using many whiles. Those "few lines" add up. Any script that can be made to be smaller,faster,or more readable im just not seeing a downside here.


It's called reusable code, you simply script something that can be used over and over again by many different events/aliases. It CAN be done in mIRC, I do so daily.
.


--

katsklaw
Rather experienced Admin
Rather experienced mIRC Scripter
Amateur C Coder
Re: For Loops #62293 27/12/03 03:00 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
What does adding a for loop have to do with reuseable code? As has been said by myself and several others, a scripted for loop would be limited beyond useability.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Page 1 of 2 1 2