PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: #)[Next]: #}
\ -> Commands -> #{


This command is used to define the start of a loop which ends with the "#}" statement. Loops can be used within a macro.


[WhiteSpace]#{  [FOR RexxVariable = Start TO End] or
[WhiteSpace]#{  [SET [COUNTER RexxVar] ["]SetSpec1["] ...]

The syntax directly supports simple "for" loops and "set" loops, for more complicated requirements you would need to do your own end of loop processing.

The #continue command can be used to restart at the top of the loop and #break will cause you to exit the loop.

FOR Loops

Probably fairly obvious but you are looping through all integers from a starting point and incrementing by one until the ending point is reached. Both the "start" and "end" values may be either rexx numbers or variables.

SET Loops

The idea behind a set loop is that you have one or more sets of values which you'd like to process, effectively this can provide a nested loop like functionality.

A set is simply an array containing items (possibly created using Add2() or ArraySplit()). In general having duplicated entries would make no sense but this is not validated.

If a set specification contains an equals sign then you wish to create a set of data by splitting the string after the equal sign. By default a space is used as a delimiter, to override this preceed the string with '{Delimiter}'. Leading and trailing whitespace is always removed and blank items ignored.

If set "a" contains 10 items, set "b" contains 3 and set "c" contains 4 and you specified "SET A B C" then the loop will be executed 10x3x4=120 times as every combination will be processed.

To access the current values of the sets within the loop you use rexx variables "SET_A", "SET_B" and "SET_C". The names must be valid as rexx symbols. There is no built in limit on the number of set items and the left most item varies slowest until the right most which varies fastest.

If you specify a "COUNTER" name then you can use this variable within the loop, it will start at one and increment for each combination processed.


  1. Both the start and end of a loop must occur within the same input file.

  2. Loops can't be nested (within a single file).

    If you need to nest loops you can either use the #include command to include a file which then itself contains a loop or you do a bit of rexx programming.

  3. Since PPWIZARD loads the whole loop without processing lines in between the affect of any intermediate "HashPrefix" option is ignored for the purposes of finding the end of the loop.

Example 1 - FOR Loop (Value = 1 to ?)

We wish to create 99 printer definitions in a Jetform JMD, these will look like:

!p PRINTR01 PRINTR01 PRINTR01/q "-afx...
!p PRINTR99 PRINTR99 PRINTR99/q "-afx...

The code to generate these printer definitions is:

;--- Define 99 SSP Printers ---
#RexxVar SspPrinter = 1
   ;--- Make sure we use "01" - "99" ---
   #if [<??SspPrinter> < 10]
       #evaluate ^^ ^SspPrinter = '0' || SspPrinter^    ;;Does not affect addition

   ;--- Create the printer ---
   !p PRINTR<??SspPrinter> PRINTR<??SspPrinter> PRINTR<??SspPrinter>/q "-afxon -apfon -axpson -asplex616p -rYES -aduON" 50

   ;--- Finished? ---
   #RexxVar SspPrinter + 1      ;;Add 1 to count
   #if [<??SspPrinter> > 99]    ;;Finished?
       #break                   ;;Created all printers!

The above again but this time using a "for" loop as well as using a macro replacement tranformation (this is slower):

;--- Simple transformation to product 2 digit (minimum) integers ---
#DefineRexx REXX_$$0PadTo2
   TheValue = TheValue + 0;                ;;Strip off excess spaces and leading zeros
   if  TheValue < 10 then                  ;;Has less than 2 digits?
       TheValue = right(TheValue, 2, '0'); ;;Left pad to 2 digits

;--- The code to produce 99 printer definitions ---
#{ for SspPrinter = 1 to 99
   ;--- Create a printer ---
   !p PRINTR<??SspPrinter $$0PadTo2> PRINTR<??SspPrinter $$0PadTo2> PRINTR<??SspPrinter $$0PadTo2>/q "-afxon -apfon -axpson -asplex616p -rYES -aduON" 50

Example 2 - FOR Loop (file list)

The following code lists all graphics files with the extension ".GIF" along with its height and width:

#DefineRexx ''
   ;--- Get list of GIF files (sort it) ---
   call Files4Mask "D:\DBAREIS\Projects\HOMEPAGE\graphics\*.gif", "gif",,"Y"

;--- The "GIF" array now holds the list of files (GIF.0 = count) ---
<p>There are <??gif.0> GIF files available as follows:
   ;--- List all the GIFs ----------
   #{ FOR GifNumber = 1 to gif.0
      ;--- Output full filename ----

      ;--- Lets output image size --
      #evaluate ^^ ^fsize = GetImageHeightWidth(gif.GifNumber)^

Example 3 - Test "SET" loop

The following code shows 4 different variations on how set data can be created and specified.

#DefineRexx ''
   ;--- Create SET "A" ---
   A.1 = '1'
   A.2 = '4'
   A.3 = '7'
   A.0 =  3   ;;Number of Items in set "A"

   ;--- Create SET "B" ---
   call ArraySplit 'B', 'apple orange'

;--- Use the "sets" created above -------------------------------------------
#RexxVar NUMLOOPS = 0                   ;;Loop counter (Better way demonstrated below)
#{ SET A B
   #RexxVar NUMLOOPS + 1
   <??NUMLOOPS>. A = "<??SET_A>"   , B = "<??SET_B>"

;--- Create sets as part of the loop command --------------------------------
#{ SET counter NUMLOOPS                        \
       ^A=1 7 9 11^                            \
   <??NUMLOOPS>. A = "<??SET_A>"   , B = "<??SET_B>"

Example 4 - Very Simple SET Loop

    #info ^Processing item: <??SET_@@Produt>^

Example 5 - Read File Until End

This example is used to load a list of languages and to create a directory for each ones generated html. The languages file looks like:

en     ;;English
it     ;;Italian
fr     ;;French

The code (OS/2 only) to read the above file and create the directories is:

;--- Define some directories ---
#define site.root            C:\sitetest
#define site.out.dir         <$site.root>\html     ;;output root

;--- Initialization ---
#DefineRexx ''
   ;--- Load standard rexx library ---
   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
   call SysLoadFuncs

   ;--- Make required base directories ---
   MkDirRc = SysMkDir('<$site.root>')
   MkDirRc = SysMkDir('<$site.out.dir>')

;--- Make language directories ---
#define    LanguageFile   "LANG.IH"           ;;Note in this case would be more CPU efficent if rexx variable
#DependsOn INPUT <$LanguageFile>
#evaluate "" ^CloseFileRc = stream(<$LanguageFile>, 'c', 'close');^
   ;--- Exit on EOF ---
   #if  lines(<$LanguageFile>) = 0

   ;--- Read the language line, strip out comment and make directory ---
   #evaluate "" "MkDirRc=SysMkDir('<$site.out.dir>\' || '<?=word(linein(<$LanguageFile>), 1)>')"
#evaluate "" ^CloseFileRc = stream(<$LanguageFile>, 'c', 'close');^

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: #)[Next]: #}

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am