Bugfix around foreach

Remored the ERROR_CHECK at the last line of the foreach function.
If the is an ERROR_CHECK in this position,
it catches the error status from "while".