foreach.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. foreach
  2. -------
  3. Evaluate a group of commands for each value in a list.
  4. ::
  5. foreach(loop_var arg1 arg2 ...)
  6. COMMAND1(ARGS ...)
  7. COMMAND2(ARGS ...)
  8. ...
  9. endforeach(loop_var)
  10. All commands between foreach and the matching endforeach are recorded
  11. without being invoked. Once the endforeach is evaluated, the recorded
  12. list of commands is invoked once for each argument listed in the
  13. original foreach command. Before each iteration of the loop
  14. ``${loop_var}`` will be set as a variable with the current value in the
  15. list.
  16. ::
  17. foreach(loop_var RANGE total)
  18. foreach(loop_var RANGE start stop [step])
  19. Foreach can also iterate over a generated range of numbers. There are
  20. three types of this iteration:
  21. * When specifying single number, the range will have elements [0, ... to
  22. "total"] (inclusive).
  23. * When specifying two numbers, the range will have elements from the
  24. first number to the second number (inclusive).
  25. * The third optional number is the increment used to iterate from the
  26. first number to the second number (inclusive).
  27. ::
  28. foreach(loop_var IN [LISTS [list1 [...]]]
  29. [ITEMS [item1 [...]]])
  30. Iterates over a precise list of items. The ``LISTS`` option names
  31. list-valued variables to be traversed, including empty elements (an
  32. empty string is a zero-length list). (Note macro
  33. arguments are not variables.) The ``ITEMS`` option ends argument
  34. parsing and includes all arguments following it in the iteration.