HPlogo System Debug Reference Manual > Chapter 5 System Debug Command Specifications Fx-LOG

FOREACH

MPE documents

Complete PDF
Table of Contents
Index

E0201 Edition 4 ♥
E0300 Edition 3
E0692 Edition 3

Each time a FOREACH command is executed, name is set to the next expression value in value_list prior to the execution of cmdlist. Execution ends when there are no more expression values in the value_list.

Syntax



   FOREACH  name  value_list      command

   FOREACH  name  value_list    { cmdlist }

Parameters


name

The name for the control variable that is set to the next expression value in value_list. A local variable is declared automatically, and it can be referenced with the cmdlist.

An optional type specification can be appended to the variable name, in order to restrict/convert the values in the list to a specific desired type:


   foreach j:S16 '1 2 3+4 5' {wl j }

If the type specification is omitted, the type ANY is assumed.

value_list

This is a quoted string (or string variable) that contains a list of values (expressions). The cmdlist is evaluated once for every expression in the list. The list may contain string and or numeric expressions.

command cmdlist

A single command (or command list) that is executed for each value in value_list.

Examples



   %cmdebug > foreach j '1 2 3 "MOM" date 12.330' wl j
   $1
   $2
   $3
   MOM
   WED. SEPT 3, 1986
   $12.00000330

A local variable j is assigned each of the expression values in the value list string, and the specified command references the current value of j in order to write its value.

   $nmdebug > foreach j '6  -2  "a" + "b"  3 +4' {wl j}
   $4
   "ab"
   $7

This example shows that full expression values are evaluated within the value list.

   $nmdebug > var nums '"1" "2" "3"'
   $nmdebug > var lets '"A" "B" "C"'
   $nmdebug > foreach l lets { foreach n nums {wl l n }}
   A1
   A2
   A3
   B1
   B2
   B3
   C1
   C2
   C3

This is an example of nested FOREACH commands that use string variables for their value lists.

Limitations, Restrictions


none




FINDPROC


FPMAP