Home / lang / foreach 
Previous  Next  Edit  Rename  Undo  Refresh  Search  Administration   
fr  de  es  it  nl  pl  pt  pt_BR  mk  ca  ar  fa  vi  ja  ru  zh  zh_TW  eo 
Documentation
History
 
FOR EACH
Syntax
FOR EACH Variable IN Expression
  ...
NEXT

Repeats a loop while enumerating an object.

Expression must be a reference to an enumerable object: for example, a collection, or an array.

Examples

DIM Dict AS NEW Collection
DIM Element AS String

Dict["Blue"] = 3
Dict["Red"] = 1
Dict["Green"] = 2

FOR EACH Element IN Dict
  PRINT Element;
NEXT

3 1 2

FOR EACH
Syntax
FOR EACH Expression
  ...
NEXT

This syntax must be used when Expression is a enumerable object that is not a real container: for example, the result of a database query.

DIM Res AS Result

Res = DB.Exec("SELECT * FROM MyTable")

FOR EACH Res
  PRINT Res!Code; " "; Res!Name
NEXT

The order of the enumeration in not necessarily predictable. See the documentation of each enumerable class for more details on that.

See also

Loop Control Structures  Native Container Classes