[Gambas-user] Documentation of FOR EACH

Benoît Minisini gambas at ...1...
Mon Oct 26 20:27:31 CET 2009


> http://gambasdoc.org/help/lang/foreach
> 
> "The order of the enumeration in not necessarily predictable. See the
> documentation of each enumerable class for more details on that."
> 
>  I can't find any else information on that topic.
>  What does that mean?
> 
> Jussi
> 

It means that sometimes the order of elements is predictable, sometimes it is 
not.

If you enumerate an array or a collection, the order is predictable. Arrays 
are enumerated by index, while collections are enumerated by following the 
element creation order.

The following code:

	Dim aArray As New String[] = [ "blue", "white", "red" ]
	Dim aCol As New Collection = [ "a": "blue", "b": "white", "c": "red" ]
	Dim sVal As String

	For Each sVal in aArray
	  Print sVal;;
	Next
	Print

	For Each sVal in cCol
	  Print sVal;;
	Next
	Print

will print:

	blue white red
	blue white red

For other enumerable classes, you must suppose that the order of enumeration 
is random, unless the contrary is explicitely written in the class 
documentation.

Regards,

-- 
Benoît Minisini




More information about the User mailing list