mIRC Home    About    Download    Register    News    Help

Print Thread
Displaying variables in a while loop #235329 09/12/11 03:32 PM
Joined: Dec 2011
Posts: 4
C
curillo Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Dec 2011
Posts: 4
I have been searching and trying for hours, but I can't make it work:

Let's say I have variables called
%test.1
%test.2
...
%test.10

Now I want to use a while loop to display them all. Something like:

var %i = 1
while (%i <= 10) {
echo 2 %test.%i
inc %i
}

The above code doesn't work. How do I make it work?

Thanks!

Re: Displaying variables in a while loop [Re: curillo] #235332 09/12/11 04:44 PM
Joined: Jan 2004
Posts: 1,214
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,214
try changing

echo 2 %test.%i

into

echo 2 %test. [ $+ [ %i ] ]

Re: Displaying variables in a while loop [Re: maroon] #235337 09/12/11 09:08 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Or:

Code:
echo 2 $($+(%,test.,%i),2)


Invision Support
#Invision on irc.irchighway.net
Re: Displaying variables in a while loop [Re: Riamus2] #235340 09/12/11 11:14 PM
Joined: Dec 2011
Posts: 4
C
curillo Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Dec 2011
Posts: 4
Thanks for the replies. Unfortunately, neither of those work for me.

Re: Displaying variables in a while loop [Re: curillo] #235341 09/12/11 11:19 PM
Joined: Dec 2011
Posts: 4
C
curillo Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Dec 2011
Posts: 4
Oh, wait... the second one works when put in an alias, but not when doing a straight /echo

Re: Displaying variables in a while loop [Re: curillo] #235342 09/12/11 11:20 PM
Joined: Dec 2011
Posts: 4
C
curillo Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Dec 2011
Posts: 4
Never mind. I must have mistyped something. They both work in an alias.

Thanks!

Re: Displaying variables in a while loop [Re: curillo] #235343 10/12/11 01:29 AM
Joined: Jan 2004
Posts: 1,276
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,276
You need to use two slashes to evaluate identifiers in the edit box: //echo -a $pi (and of course your variable would need to be global or defined in the same command)

Last edited by Loki12583; 10/12/11 01:30 AM.