HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/ircII/help/foreach
!	 $eterna: foreach,v 1.10 2021/03/21 04:29:43 mrg Exp $
!
! Copyright (c) 1990-2021  Michael Sandrof, Troy Rollo, Matthew Green,
! and other ircII contributors.
!
! All rights reserved.  See the HELP IRCII COPYRIGHT file for more
! information.
!
Usage: FOREACH <structure> <variable> { <commands> }
       FOR <structure> <variable> { <commands> }
       FOR (<commence,<evaluation>,<iteration>) { <commands> }
  This causes <commands> to be executed once for each 
  element in the structure.  The aliases inside the {} 
  are not expanded until execution unless the leading { 
  is quoted like \{
  The 2nd style of FOR allows C-style for loops.
  Here are a couple examples of basic foreach commands.
    assign blue.1 one
    assign blue.2 two 
    assign blue.3 three
    foreach blue ii { echo $ii $blue[$ii] }
  will return
    1 one
    2 two
    3 three
  FOREACH can also be imbedded such as in the following example.
    assign blue.1.1 one one
    assign blue.1.2 one two
    assign blue.2.1 two one
    assign blue.2.2 two two
    alias showblue {
      foreach blue ii
      {
        foreach blue.$ii jj
        {
          echo $ii $jj $blue[$ii][$jj]
        }
      }
    }
  And /showblue returns.. 
    1 1 one one
    1 2 one two 
    2 1 two one
    2 2 two two

Note:
  When using this format the {} in the foreach must be on separate 
  lines by themselves.  This is true for IF and WHILE as well.

  Notice that variable names 'ii' and 'jj' were used.  Any name can
  be used for the index but keep in mind that single letter vars can
  interfere with the built in single char vars.  See ALIAS special

See Also:
  expressions
  ALIAS special