mIRC Home    About    Download    Register    News    Help

Page 1 of 2 1 2 >
Topic Options
#8140 - 24/01/03 11:16 PM for statement
SubSpace Offline
Ameglian cow

Registered: 29/12/02
Posts: 25
I know there is a while statememt, but every now and then (when I'm still waking up) I forget an 'inc %i' statement that would never happen if it were in some for-like syntax.

Result: aborted DCC sends smirk


Edited by SubSpace (24/01/03 11:17 PM)

Top
#8141 - 25/01/03 01:50 AM Re: for statement
theRat Offline
Hoopy frood

Registered: 11/12/02
Posts: 774
solutions:
1. Don't forget the 'inc %i'
2. Create scripts on second instance of mIRC
3. Don't use DCC while creating scripts
4. Don't use DCC at all
5. Don't create scripts when you're still waking up
... laugh
_________________________
Code:
//if ( khaled isgod ) echo yes | else echo no

Top
#8142 - 25/01/03 02:01 AM Re: for statement
SubSpace Offline
Ameglian cow

Registered: 29/12/02
Posts: 25
6. Just add the <censored> for statement wink

Top
#8143 - 25/01/03 04:29 AM Re: for statement
Sabby Offline
Babel fish

Registered: 03/01/03
Posts: 94
Loc: Michigan, USA
hm, i too would like the for() inscripted in mIRC, though some people wont use it because mIRC has while() and :loops..

but still never hurts to have more options.
_________________________
-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk

Top
#8144 - 25/01/03 04:41 AM Re: for statement
Gon_ Offline
Babel fish

Registered: 21/12/02
Posts: 56
I would like this too. A FOR loop uses less code than a WHILE loop. That is an advantage. A 1 line FOR loop can be more elegant than a WHILE loop, imo, that is good too. There is also a chance that it *might* be faster than a WHILE loop, because your not using an interpreted script command to inc it, mIRC would do that internally. Im not trying to justify this addition on possible speed gain though, there might be none. It's nice to add new things to essence of the scripting language. A for loop is preferable to some, and save you a few bytes in code, so why not?

Top
#8145 - 25/01/03 06:24 PM Re: for statement
codemastr Offline
Hoopy frood

Registered: 12/12/02
Posts: 2809
:loops are horrible horrible horrible! They have been shunned in just about every language they exist in. 'goto' is a dreaded operation in just about every language. Most languages have multiple ways to create a loop (each designed to make code more readable in certain situations). A while() loop is useful when no initialization is needed and a non-standard iteration, for example
while (%i != 4)
{
echo %i
if (%i == 2) {
inc %i 2
}
else {
inc %i
}
}

Notice how depending on the value of %i, the iteration is done differently.

For loops are different, they are used when initialization is needed and the iteration is standard:

for (%i = 0; %i != 4; inc %i)
{
echo %i
}

Then do while loops are used when you want to execute the body of the loop before checking the conditional:

do {
echo %i
inc %i
} while (%i != 4)

Those are the standard ones, but some languages even go farther than that. For example foreach which returns an entry in a list (useful for mIRC tokens)

foreach %tok ($1-) {
echo %tok
}

that would echo the value of $1, $2, etc. Could even be expanded say

foreach %tok ($1-,32) {
echo %tok
}

where the 32 (space) is the token to seperate by.

Then there are less common loops (primarily in perl). For example perl has an until() loop which continues until the expression evaluates to true, (rather than a while which waits till it evaluates to false). It also has do {} until() which does the same thing as until() except it follows the rules of do {} while(). And from what I'm told the newest versions of perl even go one step further and have a loop called loop {} which basically creates an infinite loop (same as doing while(1) { }).

Ok now I agree implementing all of those would be overkill, but my point is simply saying "there are other ways to create a loop" wasn't good for any of the other languages out there, so why should that be a good enough excuse for mIRC?

Top
#8146 - 25/01/03 08:33 PM Re: for statement
Sabby Offline
Babel fish

Registered: 03/01/03
Posts: 94
Loc: Michigan, USA
actually :loops can be very useful

if you use this kind of scripting style, for example dialogs:

on *:dialog:whatever:sclick:*:{
goto $did

:1
blah

:2
blah2

:3
blah3
}
_________________________
-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk

Top
#8147 - 25/01/03 08:41 PM Re: for statement
codemastr Offline
Hoopy frood

Registered: 12/12/02
Posts: 2809
I didn't say they aren't useful, I said that they are bad. There is a difference. What you just did there would be much better suited with a switch() statement, which IMHO should also be added to mIRC.

Top
#8148 - 25/01/03 10:59 PM Re: for statement
Sabby Offline
Babel fish

Registered: 03/01/03
Posts: 94
Loc: Michigan, USA
agreed
_________________________
-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk

Top
#8149 - 26/01/03 03:04 AM Re: for statement
BoredNL Offline
Vogon poet

Registered: 15/01/03
Posts: 154
on *:dialog:whatever:sclick:*:{
goto $did

:1
echo ok, it's 1

:2
echo ok, it might be 2.. or 1.. who knows?

:3
echo hmm.. It might be 2, 3, or 1? I see no end to this!

:4
echo I'm confused now, please leave me alone.

:5
echo AHH!!

}
_________________________
- Wherever you go there you are.[color:lightgreen]

Top
#8150 - 26/01/03 03:23 AM Re: for statement
Sabby Offline
Babel fish

Registered: 03/01/03
Posts: 94
Loc: Michigan, USA
huh?
_________________________
-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk

Top
#8151 - 26/01/03 03:56 AM Re: for statement
Gon_ Offline
Babel fish

Registered: 21/12/02
Posts: 56
Quote:

actually :loops can be very useful

if you use this kind of scripting style, for example dialogs:

on *:dialog:whatever:sclick:*:{
goto $did

:1
blah

:2
blah2

:3
blah3
}


That isn't a loop though, that is just a GOTO jump wink

GOTO is very useful yes. But using it for looping isnt as fast as a WHILE loop in mIRC.

Top
#8152 - 26/01/03 04:04 AM Re: for statement
Sabby Offline
Babel fish

Registered: 03/01/03
Posts: 94
Loc: Michigan, USA
ok, i posted that because i thought he ment that :stuff isnt usefull.. now i see what he means by like

var %i = 1
:blargh
echo -a %i : $chr(%i)
if (%i <= 255) goto blargh
else return
_________________________
-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk

Top
#8153 - 26/01/03 06:04 AM Re: for statement
SergioNL Offline
Babel fish

Registered: 09/12/02
Posts: 54
Loc: netherlands
just do CTRL + pause/brake if that exidently happens and fix your bug afterwards(it wil show exactly wich line it stopped)

Top
#8154 - 26/01/03 08:58 AM Re: for statement
Hammer Offline
Hoopy frood

Registered: 07/12/02
Posts: 1321
Loc: Georgia, USA
Quoting codemastr talking about GOTO:

Quote:

I didn't say they aren't useful, I said that they are bad (emphasis added). There is a difference.


Wrong. GOTO is not inherently bad. It has been abused over the years rather dramatically, leading to spaghetti code that's all but impossible to follow, that's true enough. Blaming that on GOTO is ridiculous. Blame the ignorant or just plain poor coder(s), not the inappropriate use of a language feature.

I assume that you've been coding for more than 12 minutes. Think about error trapping. I will grant you that I can't think of a reason offhand to use goto instead of calling an error alias that halts the script. Perhaps if there was some necessary cleanup for a graceful exit that would preclude using a central alias.
_________________________
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C

Top
#8155 - 26/01/03 10:50 AM Re: for statement
Gon_ Offline
Babel fish

Registered: 21/12/02
Posts: 56
I think Codemastr meant that GOTO was bad for looping, and not that all uses of GOTO are bad.
For instance, i can't think of 1 single advantage a GOTO loop has over a WHILE loop, other than backwards compatability with old mIRC versions.

Top
#8156 - 26/01/03 12:16 PM Re: for statement
Hammer Offline
Hoopy frood

Registered: 07/12/02
Posts: 1321
Loc: Georgia, USA
I quite agree with him on that: GOTO is inferior to WHILE for looping. I also agree that 90+% of the code that I've seen in mIRC script that uses GOTO in it is badly scripted (from many points of view). My only objection to what he said was that GOTO, in and of itself, is "bad."
_________________________
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C

Top
#8157 - 26/01/03 02:52 PM Re: for statement
Doqnach Offline
Hoopy frood

Registered: 18/01/03
Posts: 1063
GOTO loops are very usefull with initialisation of scripts...

you ask for inputs, and check afterwards if they add up, if not you have the script return...

there is nothing a for loop can do what a "var %i = 1 | while (%i <= 10) { bla | inc %i }" can't do... just a little more code. imo mIRC script should stay easy, and not become a coding language on itself
_________________________
If it ain't broken, don't fix it!

Top
#8158 - 26/01/03 03:57 PM Re: for statement
scoob Offline
Self-satisified door

Registered: 23/01/03
Posts: 3
Quote:
GOTO is very useful yes. But using it for looping isnt as fast as a WHILE loop in mIRC.


this isn't 100% true, any and all work I've done listing to a @window using echo and/or aline has been noticeably quicker using goto loops.

Top
#8159 - 26/01/03 05:53 PM Re: for statement
SubSpace Offline
Ameglian cow

Registered: 29/12/02
Posts: 25
GOTO for error handling is appalling, any time, any day..
In fact, using GOTO for anything I can think of is pretty bad coding.

GOTO is the statement that is removed from every self respecting higher level language, or should be.

And regarding spaghetti code, it will come to no surprise to you that I happen to disagree. Sure, it's easy enough to make unreadable code, but it's pretty much impossible to make spaghetti code without GOTO.

Spaghetti code refers to the habit that some people used to have to jump into loops and subroutines halfway and jump back out at will. This makes the control structure pretty much ununderstable to anyone but maybe the programmer. This is impossible if you only have conditional statements, subroutines, while-like loops and structured exception handling.

Edit: typos


Edited by SubSpace (26/01/03 06:05 PM)

Top
Page 1 of 2 1 2 >