Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The foreach loop in most programming languages comes to an end when it has iterated over all the elements in the collection or array it is iterating over. It does not stop when a null value is encountered, as null values are often valid elements in collections. The loop will keep iterating until it has looped over all the elements in the collection, and then it will terminate.