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."
|