SUNiNET - Your Eggdrop & TCL resources site
[ Home Eggdrop TCL Links About ]

Guide to TCL scripting for Eggdrop 1.6


[ Previous ] [ Index ] [ Next ]


10.3 Looping for a number of times

The third and final loop is the for loop.
This loop is fairly simple and is mostly used when somebody wants to loop something for a number of times.
The syntax of a for command is for { <start> } { <check> } { <loop> } { <body> }.

The <start> is the command you want to be executed before the loop starts.
This can be setting a string to 0 for instance.

The <check> is the check that is made while the loop is running and works in the same way as the check in the while loop.

The <loop> is the command you want to be executed every time a loop has ended.
This can be increasing a string with 1 for instance.

Here is an example of a for loop:

set test "[chanlist #eggdrop]"
set ops 0
for { set number 0 } { $number < [llength $test] } { incr number } {
  if {[isop [lindex $test $number] #eggdrop]} {
    incr ops
  }
}
puthelp "PRIVMSG #eggdrop :There are currently $ops people opped in #eggdrop."


[ Previous ] [ Index ] [ Next ]


Design & Graphics by Shawn Borton
Copyright © 2000-2005 Marijn van Zon