# foreach

Iteration command

Syntax

    foreach(<variable>,[<item>[,<item>[,<item>[...]]]) <command>

Description

Executed <command> while assigning to <variable> each <item>.
<item> may be a constant , a variable , an array , a dictionary or a function returning either a constant string an array reference or a dictionary reference.
If <item> is an array , a dictionary or a function that returns a dictionary or array reference the iteration is done through all the dictionary/array items.
Please note that the iteration order of dictionary items is undefined.
You can always break from the loop by using the break command.

Examples

        foreach(%i,1,2,3,4,5,6,7,8,9)echo %i
        foreach(%chan,$window.list(channel))me -r=%chan This is a test!
        # This will work too, and will do the same job
        %windows[] = $window.list(channel)
        foreach(%chan,%windows[])me -r=%chan This is a test!
        # And this too
        %windows[] = $window.list(channel)
        foreach(%key,%windows[]@)me -r=%windows[%key] This is a test!

Main index, Command index

KVirc 3.0.0 documentation
Generated by root at Thu Apr 29 12:41:05 2004