fix the foreach function
Revert "fix on the if then else condition"

This reverts commit 8047790919d79824a86eee01ce16bc6a626291b7.