mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
for statement #8140 24/01/03 11:16 PM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
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

Last edited by SubSpace; 24/01/03 11:17 PM.
Re: for statement #8141 25/01/03 01:50 AM
Joined: Dec 2002
Posts: 774
T
theRat Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
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
Re: for statement #8142 25/01/03 02:01 AM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 25
6. Just add the <censored> for statement wink

Re: for statement #8143 25/01/03 04:29 AM
Joined: Jan 2003
Posts: 94
S
Sabby Offline
Babel fish
Offline
Babel fish
S
Joined: Jan 2003
Posts: 94
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
Re: for statement #8144 25/01/03 04:41 AM
Joined: Dec 2002
Posts: 56
G
Gon_ Offline
Babel fish
Offline
Babel fish
G
Joined: Dec 2002
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?

Re: for statement #8145 25/01/03 06:24 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
: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?

Re: for statement #8146 25/01/03 08:33 PM
Joined: Jan 2003
Posts: 94
S
Sabby Offline
Babel fish
Offline
Babel fish
S
Joined: Jan 2003
Posts: 94
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
Re: for statement #8147 25/01/03 08:41 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Re: for statement #8148 25/01/03 10:59 PM
Joined: Jan 2003
Posts: 94
S
Sabby Offline
Babel fish
Offline
Babel fish
S
Joined: Jan 2003
Posts: 94
agreed


-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk
Re: for statement #8149 26/01/03 03:04 AM
Joined: Jan 2003
Posts: 154
B
BoredNL Offline
Vogon poet
Offline
Vogon poet
B
Joined: Jan 2003
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]
Re: for statement #8150 26/01/03 03:23 AM
Joined: Jan 2003
Posts: 94
S
Sabby Offline
Babel fish
Offline
Babel fish
S
Joined: Jan 2003
Posts: 94
huh?


-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk
Re: for statement #8151 26/01/03 03:56 AM
Joined: Dec 2002
Posts: 56
G
Gon_ Offline
Babel fish
Offline
Babel fish
G
Joined: Dec 2002
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.

Re: for statement #8152 26/01/03 04:04 AM
Joined: Jan 2003
Posts: 94
S
Sabby Offline
Babel fish
Offline
Babel fish
S
Joined: Jan 2003
Posts: 94
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
Re: for statement #8153 26/01/03 06:04 AM
Joined: Dec 2002
Posts: 54
S
SergioNL Offline
Babel fish
Offline
Babel fish
S
Joined: Dec 2002
Posts: 54
just do CTRL + pause/brake if that exidently happens and fix your bug afterwards(it wil show exactly wich line it stopped)

Re: for statement #8154 26/01/03 08:58 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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
Re: for statement #8155 26/01/03 10:50 AM
Joined: Dec 2002
Posts: 56
G
Gon_ Offline
Babel fish
Offline
Babel fish
G
Joined: Dec 2002
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.

Re: for statement #8156 26/01/03 12:16 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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
Re: for statement #8157 26/01/03 02:52 PM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
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!
Re: for statement #8158 26/01/03 03:57 PM
Joined: Jan 2003
Posts: 3
S
scoob Offline
Self-satisified door
Offline
Self-satisified door
S
Joined: Jan 2003
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.

Re: for statement #8159 26/01/03 05:53 PM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
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

Last edited by SubSpace; 26/01/03 06:05 PM.
Page 1 of 2 1 2