Novelty scripting reference > Keywords > foreach

foreach

'foreach' is a keywords that is not normally part of the Angelscript language but has been added in Novelty. It behaves like a for-loop but will let you loop over every element in an array.


Syntax

foreach (Type T in Array)

Type must match the type of the array or be of compatible type.

Angelscript equivalence

for (uint _it = 0; _it < Array.Length(); ++_it) {
	Type T = cast<Type>(Array[_it]);
	...
}


Sample

// Print the names of all objects in the scene
array<Object@> List;
Scene.EnumerateObjects(List);
foreach (Object@ o in List)
	Print(o.name);

See also: Scene.EnumerateObjects


Back to top